GetAllAccounts() { -6ren">
gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 18:11:56 25 4
gpt4 key购买 nike

如果我在 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com