.net - 使用稍微复杂的方法引用 WCF 服务时获取 "Recursive collection data contract"

标签 .net wcf exception-handling wsdl

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

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

从另一个项目引用服务时出现此错误:

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



如果我删除上述方法,重新编译并更新引用,则它可以正常工作。但是当我添加上述方法时,我始终收到此警告。

我发现的一个建议是卸载 Visual Studio 2012 并修复 Visual Studio 2010。我不想这样做。

另一个 suggested取消选中“在所有引用的程序集中重用类型”,但这会弄乱方法签名并且不可用。

最佳答案

事实证明,错误是由于我从 NuGet 安装了一个 Microsoft Web API 包,其中包括 Json.NET。卸载这个后,它工作正常。

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

关于.net - 使用稍微复杂的方法引用 WCF 服务时获取 "Recursive collection data contract",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12069176/

相关文章:

.net - .cer 和 .pfx 文件有什么区别

c# - 如何提高 HashSet 使用时的速度以确保不生成重复记录

c# - HTTPWebResponse 原始响应,使用反射

windows - Netsh 和 httpcfg

ruby - 我可以在 Ruby 中 stub "raise"吗?

vb.net - 处理VB中的全局异常

.net - 执行时出现简单 WCF 服务错误

c# - 我可以根据 URL 和方法名称调用 Web 服务吗?

c# - 通过 WCF 服务传递指定的泛型类型

.net - 我可以避免在调试器附带调试器的情况下避免缓慢的.net异常吗?