简体   繁体   English

WCF中的字典

[英]Dictionary in wcf

I have an WCF service which contains a method that returns a Dictionary. 我有一个WCF服务,其中包含一个返回Dictionary的方法。

The generated method in the proxy class returns ArrayOfKeyValueOfstringstringKeyValueOfstringstring array. 代理类中生成的方法返回ArrayOfKeyValueOfstringstringKeyKeyValueOfstringstring数组。 how can i use this method ? 我如何使用这种方法?

The contract method : 合同方式:

        [OperationContract]
        Dictionary<string, string> GetESGKeywordQuestion();

In the proxy class i have 

ArrayOfKeyValueOfstringstringKeyValueOfstringstring[] GetESGKeywordQuestion()
{
// code
}

The accepted answer in another similar thread reference to a link telling you how to have Dictionary at the client side in .NET to .NET communication. 另一个相似的线程引用中的可接受答案是指向链接的链接,该链接告诉您如何在.NET到.NET通信的客户端上使用Dictionary In other words, poor interoperability if you want your service to be consumed by non-dot-net applications like PHP or Java etc. If you had learned/remember data structure in CS, you know dictionary is implemented through non-linear structure like B-tree, so dictionary is not likely to be included in WSDL because of the complexity and variant. 换句话说,如果您希望服务被非点网应用程序(例如PHP或Java等)占用,则互操作性较差。如果您已经在CS中学习/记住了数据结构,则您知道字典是通过非线性结构(如B)实现的-tree,因此由于复杂性和变型,字典不太可能包含在WSDL中。 The ArrayOfKeyValueOfstringstringKeyValueOfstringstring structure generated for client is well designed and intended. 为客户端生成的ArrayOfKeyValueOfstringstringKeyValueValuestring字符串结构经过精心设计和预期。 If you want to see consistency on both side and want interoperability, then don't use Dictionary, instead, use a linear structure such as an array of KeyValuePair. 如果要双方都看到一致性并希望互操作,请不要使用Dictionary,而应使用线性结构,例如KeyValuePair数组。

the generated proxy class seems to be wrong.. 生成的代理类似乎是错误的。

Try changing it to return the required Dictionary manually.. 尝试更改它以手动返回所需的Dictionary

Dictionary<string, string> GetESGKeywordQuestion()
{
    //code
}

And this should allow you to use you GetESGKeywordQuestion() method from your WCF service 这应该允许您从WCF服务中使用GetESGKeywordQuestion()方法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM