I have a soap web service with method:
string startReaction(object reaction);
Inside that method I convert this object to it’s real type:
Reaction reactionObj = (Reaction)reaction;
...
I have the same Reaction class in the form project (windows for that should invoke this ws). Here I make Reaction object instance and fill it with data and try to send to web service.
string data = webserviceReference1.startReaction(reaction);
I have also tried:
string data = webserviceReference1.startReaction(reaction as object);
but nothing.
Then I try to add this attribute on Reaction class:
[XmlInclude(typeof(object))]
public class Reaction{...
but nothing.
The error that I get is:
There was an error generating the XML document. :: System.InvalidOperationException: The type Demo.Form1+Reaction was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically.
You must expose the
Reactionclass in the metadata of the sevrice so that the clients know about it:You should not redefine the same class on the client because that won’t work. The server wouldn’t know how to serialize it. The correct way is to have the web service expose all known types in the WSDL so that when you generate a strongly typed proxy on the client all those types will be imported and you will be able to invoke the service.