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

查看:24
本文介绍了获取“递归收集数据契约"使用稍微复杂的方法引用 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:inetpubwwwrootMyclientProjectServiceReferencesNodeServiceReference.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:inetpubwwwrootMyclientProjectService ReferencesNodeServiceReference.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天全站免登陆