Web service call failed. Use the XmlInclude or SoapInclude attribute.
I make a call to another web service, they provided a WSDL file and a bunch of XSD files. I created a web link in my project using a local WSDL file and created a class using xsd.exe. The web method I am calling is
object MyService.MyMethod(object myObj)
So, I am creating a new instance of my service and a new instance of the object created by xsd. The web service documentation tells me that myObj is of type ObjectRQ (generated from xsd).
My code looks like this:
MyService service = new MyService();
ObjectRQ request = new ObjectRQ();
// Set the values of request.
object result = service.MyMethod(request);
On the last line of this code, I get an error:
ObjectRQ type was not expected. Use the XmlInclude or SoapInclude attribute to indicate types that are not statically known.
I don't know what might be causing this error, and my search has brought nothing useful. Can anyone help me with this?
source to share
Since the type of the parameter in the proxy object is an object, the XmlSerializer that composes your messages is unaware of the type of ObjectRQ. In this sense, it was unexpected. So basically what you have to do is let the XmlSerializer know, one way or another, to expect this type. One way is with the XmlInclude attribute. Another way is to add the type to the known operation types of the proxy class. In a data contract, you must do this using the KnownType attribute, but since you only have control over the client, you have to do it yourself in code. You can find a blog post about this here .
NTN.
source to share