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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With