错误添加服务引用:类型是不支持递归收集数据契约 [英] Error adding service reference: Type is a recursive collection data contract which is not supported
问题描述
我尝试添加服务引用驻留在从ASP.NET MVC 4项目相同的解决方案,但没有一个WCF服务。我得到了一个错误说:
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:
自定义工具错误:未能生成code的服务引用 XXX。请检查其他错误和警告消息的详细信息。该 根警告:
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:
警告9自定义工具警告:不能导入WSDL:portType的细节:一个 在运行WSDL导入扩展抛出异常: System.ServiceModel.Description.DataContractSerializerMessageContractImporter 错误:类型Newtonsoft.Json.Linq.JToken'是一个递归集 不支持数据契约。考虑修改 集Newtonsoft.Json.Linq.JToken的定义删除 引用本身。 XPath来误差源: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:portType[@name='IXXX'] C:\项目... \ Reference.svcmap 1 pqrt.web
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
如果我删除从服务合同中的数据合同,它的工作。我也试着服务引用添加到其他项目,如库项目,甚至一个ASP.NET MVC 3的项目,它的所有工作。我想知道,这是一个问题,ASP.NET MVC 4?我使用VS 2012 RC。
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.
一个解决办法,我能想到的是将服务引用添加到库项目,然后从ASP.NET MVC 4调用库项目,但我不喜欢这样做,因为它是一个额外的步骤。有什么建议?
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?
推荐答案
如果你想保留的参考Newtonsoft.Json你也可以离开Newtonsoft.Json了组件的清单来检查datacontracts的重用。
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...
在重用类型的引用的程序集选择第二个选项来指定哪些程序集搜索重用类型和选择所有的组件,但是取消Newtonsoft.Json
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
这篇关于错误添加服务引用:类型是不支持递归收集数据契约的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!