在异步模式下调用服务时出错

时间:2022-05-23 20:58:40

* is definetly the fastest forum so after posting this question in the WCF forum I decided to come here.

*绝对是最快的论坛所以在WCF论坛上发布这个问题之后我决定来这里。

I have a wcf service which returns a dictionary (IDictionary) and that works just fine. Now I wanted to add the capability of calling that service in async mode, but when the BeginMethod gets executed I get the following Exception:

我有一个wcf服务,它返回一个字典(IDictionary),并且工作得很好。现在我想添加在异步模式下调用该服务的功能,但是当BeginMethod被执行时,我得到以下异常:

The type System.Collections.Generic.Dictionary`2[[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[TransferProp, Contracts, Version=10.1.0.0, Culture=neutral, PublicKeyToken=6f5bf81c27b6b8aa]] is not supported because it implements IDictionary.

类型System.Collections.Generic.Dictionary`2 [[System.String,mscorlib,Version = 2.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089],[TransferProp,Contracts,Version = 10.1.0.0,Culture = neutral,PublicKeyToken = 6f5bf81c27b6b8aa]]不受支持,因为它实现了IDictionary。

What's up with that?

那是怎么回事?

1 个解决方案

#1


This (CodeIdol) blog talks about deriving your own CollectionDataContract collection and returning this. Does this help?

这个(CodeIdol)博客讨论了派生自己的CollectionDataContract集合并返回它。这有帮助吗?

[CollectionDataContract]
public class MyDictionary : Dictionary<int,Contact>
{}

[ServiceContract]
interface IContactManager
{
   ...
   [OperationContract]
   MyDictionary GetContacts( );
}

#1


This (CodeIdol) blog talks about deriving your own CollectionDataContract collection and returning this. Does this help?

这个(CodeIdol)博客讨论了派生自己的CollectionDataContract集合并返回它。这有帮助吗?

[CollectionDataContract]
public class MyDictionary : Dictionary<int,Contact>
{}

[ServiceContract]
interface IContactManager
{
   ...
   [OperationContract]
   MyDictionary GetContacts( );
}