views:

446

answers:

1

I'm calling someone else's web service, they have provided a WSDL file and a bunch of XSD files. I have create the web reference in my project using the local WSDL file and created a class using xsd.exe. The web method I'm calling is

object MyService.MyMethod(object myObj)

So I create a new instance of my service and a new instance of my object created by the xsd. The web service documentation tells me that myObj is of type ObjectRQ (created from the xsd).

My code is 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 that code I get an error:

The type ObjectRQ was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically.

I don't know what could be causing this error and my search hasn't yielded anything helpful. Can anyone help me with this?

+1  A: 

Because the parameter type in your proxy is object, the XmlSerializer that composes your messages, doesn't know about the ObjectRQ type. In that sense it was unexpected. So basically what you have to do is let the XmlSerializer know, one way or the other, to expect this type. One way is the XmlInclude attribute. Another way is to add the type to the proxy class operations known types. In the data contract you would do this with the KnownType attribute, but as you only have control over the client, you'd have to do it in code, yourself. You can find a blog post about it here.

HTH.

Jonathan van de Veen
Looks like this is correct, unfortunately for me there were so many other issues with the WSDL file not creating a descent proxy that I've just given up and gone direct HTTP. Your answer was dead on though, thanks.
Odd
I appreciate your comment. Sorry to here you couldn't use my answer.
Jonathan van de Veen