获得"递归数据收集合同"一个稍微复杂的方法引用一个WCF服务时, [英] Getting "Recursive collection data contract" when referencing a WCF service with a slightly complex method

查看:306
本文介绍了获得"递归数据收集合同"一个稍微复杂的方法引用一个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:端口类型       详细信息:在运行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 \服务   参考\ NodeService \ Reference.svcmap 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.

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

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