Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error adding service reference: Type is a recursive collection data contract which is not supported

I tried to add a service reference to a WCF service that resides in the same solution from an ASP.NET MVC 4 project but failed. I got a error saying:

Custom tool error: Failed to generate code for the service reference 'XXX'. Please check other error and warning messages for details. The root warning is:

Warning 9 Custom tool warning: Cannot import wsdl:portType Detail: An exception was thrown while running a WSDL import extension: System.ServiceModel.Description.DataContractSerializerMessageContractImporter Error: Type 'Newtonsoft.Json.Linq.JToken' is a recursive collection data contract which is not supported. Consider modifying the definition of collection 'Newtonsoft.Json.Linq.JToken' to remove references to itself. XPath to Error Source: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:portType[@name='IXXX'] C:\Projects...\Reference.svcmap 1 1 pqrt.web

If I removed the data contracts from the service contract, it worked. I also tried to add the service reference to other projects like a library project or even an ASP.NET MVC 3 project, it all worked. I was wondering if this was an issue with ASP.NET MVC 4? I was using VS 2012 RC.

One workaround I can think of is to add the service reference to a library project and then call the library project from ASP.NET MVC 4, but I hate to do that since it's an extra step. Any suggestions?

like image 297
user1532001 Avatar asked Jul 18 '12 13:07

user1532001


People also ask

How to update WCF service reference?

If you do run the WCF in debug, once it loads, just go to your debug menu in VS and click "Detach All." Then update your service reference.


2 Answers

If you want to keep the reference to Newtonsoft.Json you could also leave Newtonsoft.Json out of the list of assemblies to check for reuse of datacontracts.

To do this: right click your service reference, then click Configure Service Reference...

Under "Reuse types in referenced assemblies" select the second option to specify in which assemblies to search for reused types and select all assemblies but uncheck Newtonsoft.Json

like image 109
Stif Avatar answered Oct 21 '22 02:10

Stif


Try removing Newtonsoft.Json from your references and re-add your service reference.

like image 27
JamieD77 Avatar answered Oct 21 '22 01:10

JamieD77