获得“递归收集数据契约”当使用稍微复杂的方法引用WCF服务时 [英] Getting "Recursive collection data contract" when referencing a WCF service with a slightly complex method

查看:493
本文介绍了获得“递归收集数据契约”当使用稍微复杂的方法引用WCF服务时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在WCF服务中只使用简单的方法,一切都可以正常运行。但是,如果我包含以下方法,则会出现问题:

If I use only simple methods in my WCF service, everything works fine. However, if I include the following method, a problem occurs:

[OperationContract]
public List<KeyValuePair<string, string>> GetAllAccounts()
{
    return AccountBusiness.GetAllAccounts();
}

当从另一个项目引用服务时,我收到此错误:

I get this error when referencing the service from another project:


警告5自定义工具警告:无法导入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 ='NodeService'] C:\inetpub\wwwroot\MyclientProject\Service
参考文献\NodeService\Reference.svcmap 1 1 MyClientNode

Warning 5 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='NodeService'] C:\inetpub\wwwroot\MyclientProject\Service References\NodeService\Reference.svcmap 1 1 MyClientNode

如果我删除上面的方法,重新编译和更新引用,那么它工作正常。但是当我添加上面的方法时,我一直得到这个警告。

If I remove the method above, recompile and update the reference, then it works fine. But when I add the above method, I consistently get this warning.

我发现一个建议是卸载Visual Studio 2012并修复Visual Studio 2010.我不想

One suggestion I found was to uninstall Visual Studio 2012 and repair Visual Studio 2010. I don't want to do that.

另一个建议取消选中重复使用类型在所有引用的程序集中,但这混淆了方法签名,并且不可用。

Another suggested to uncheck "Reuse types in all referenced assemblys", but this messes up the method signatures and is not usable.

推荐答案

事实证明,错误这是因为我有一个从NuGet安装的Microsoft Web API包,其中包括Json.NET。卸载后,它可以正常工作。

As it turned out, the error was caused by the fact that I had a Microsoft Web API package installed from NuGet, which included Json.NET. After uninstalling this, it works fine.

这可能是您的答案 - 如果没有,请查看您安装的其他软件包(您不需要)并删除它们。

This may be the answer for you - if not, look at which other packages you have installed (that you don't need) and remove them.

这篇关于获得“递归收集数据契约”当使用稍微复杂的方法引用WCF服务时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆