Search code examples
wcfidictionaryasynchronous-wcf-call

Error when calling the service in async mode


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

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:

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.

What's up with that?


Solution

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

    [CollectionDataContract]
    public class MyDictionary : Dictionary<int,Contact>
    {}
    
    [ServiceContract]
    interface IContactManager
    {
       ...
       [OperationContract]
       MyDictionary GetContacts( );
    }