我尝试添加对 WCF 服务的服务引用,该服务位于 ASP.NET MVC 4 项目的同一解决方案中,但失败了。我收到一条错误消息:
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
如果我从服务契约(Contract)中删除数据契约(Contract),它就会起作用。我还尝试将服务引用添加到其他项目,例如库项目甚至 ASP.NET MVC 3 项目,一切都有效。我想知道这是否是 ASP.NET MVC 4 的问题?我使用的是 VS 2012 RC。
我能想到的一个解决方法是将服务引用添加到库项目,然后从 ASP.NET MVC 4 调用该库项目,但我讨厌这样做,因为这是一个额外的步骤。有什么建议吗?
最佳答案
如果您想保留对 Newtonsoft.Json 的引用,您也可以将 Newtonsoft.Json 保留在程序集列表之外,以检查数据契约的重用。
为此:右键单击您的服务引用,然后单击“配置服务引用...”
在“引用的程序集中重用类型”下,选择第二个选项以指定在哪些程序集中搜索重用类型并选择所有程序集,但取消选中 Newtonsoft.Json
关于.net - 添加服务引用时出错 : Type is a recursive collection data contract which is not supported,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11542371/