Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom collection type is not being reused on WCF client Proxy side issue

Tags:

wcf

I have defined the following type in a class library project.

[CollectionDataContract()]
   public class OperationException:System.Collections.Generic.Dictionary<string,ExceptionData>
    {
       [DataMember()]
       public bool ExceptionExists { get; set; }
    }

   [DataContract()]
   public class ExceptionData {[DataMember()] public string Msg;}

On my WCF service end, I am returning an object which contains the above class as a child member variable like this.

[DataContract()]
public class SaveClient
{
  [DataMember()]
   public string Id;
  [DataMember()]
   public OperationException ExceptionCollection;
}

I have the OperationException class library referenced on the client side. The problem is when I generate the proxy using Add Service Reference, a new definition of OperationException of type dictionary is generated. I do have the Reuse Types option set to true. I like to have Actual 'OperationException' type being used since I have to pass this object to other methods.

Thanks in Advance..!

Iftikhar.

like image 650
Iftikhar Ali Avatar asked Oct 10 '22 13:10

Iftikhar Ali


1 Answers

I had the same issue and like you I had applied the CollectionDataContract attribute and told the proxy generator to reuse types from my shared assembly.

The fix was not obvious, you need to supply a hook in the Reference.svcmap file on your client to tell the generator to use your custom collection type.

In Reference.svcmap edit the CollectionMappings element as follows and then update the service reference:

<CollectionMappings>
  <CollectionMapping TypeName="YourSharedAssemblyNamespace.OperationException" Category="List" />
</CollectionMappings>

I think the same objective can be achieved if you are using svcutil from the command line by supplying the collection type argument.

/collectionType:YourSharedAssemblyNamespace.OperationException

See these posts for more info:

http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/09eefbbc-bf63-4aa3-a0cb-01a9dbd7f496/

http://www.codeproject.com/KB/WCF/WCFCollectionTypeSharing.aspx

I am not sure why the WCF proxy generator doesn't just use it's common sense to find the shared collection types but there you go, chalk it up as another funny from the WCF tool design.

like image 182
James Close Avatar answered Oct 13 '22 09:10

James Close