Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WCF Service reference in WCF not getting method type correct

WCF service library specifies:

[OperationContract]
void SaveData(IDictionary visitorData);

Adding a service reference in the consuming MVC project to the wcf library (must uncheck "Reuse types in referenced assemblies" to make it generate code) causes it to generate the following in Reference.cs:

public void SaveData(System.Collections.Generic.Dictionary<object, object> visitorData) {
    base.Channel.SaveData(visitorData);
}

As a result, when I call

visitorActions.SaveData(requestInfo);

(with requestInfo of type IDictionary) I get, to my utter lack of surprise, the following compiler error:

Argument 1: cannot convert from 'System.Collections.IDictionary' to 'System.Collections.Generic.Dictionary'...

Yes, I can go in and change the code to explicitly say IDictionary but Reference.cs is autogenerated and the next time I update from the service, my changes will be gone.

So what gives?

like image 581
MetalPhoenix Avatar asked Nov 10 '22 06:11

MetalPhoenix


1 Answers

The Configure Service Reference dialog box enables you to configure the behavior of generated proxies. This includes options for configuring what types are used for collections and dictionaries. If IDictionary isn't in there you might not be able to generate a proxy that uses it from within Visual Studio.

But remember that the generated clients simply exchange data in an agreed upon format. If you can get your hands on an assembly containing your service contract (or a service contract in the right format) you can use a channel factory to generate a client, instead. The format of data sent over-the-wire will be the same and therefore compatible with your service.

You can see a simple example of channel factories here.

like image 144
ta.speot.is Avatar answered Nov 14 '22 22:11

ta.speot.is