0

I've created an asp.net web service and am trying to test it using my client. The web method I'm currently testing returns a custom object named GetAllTicketsSinceLastPullDateResult, which contains one ArrayList of custom clsTrip objects, and a custom object called FaultResponse. This is how I'm using my client:

ServiceReference1.ServiceSoapClient myClient = new ServiceReference1.ServiceSoapClient();
        ServiceReference1.GetAllTicketsSinceLastPullDateResult result = new ServiceReference1.GetAllTicketsSinceLastPullDateResult();

        result = myClient.getAllTicketsSinceLastPullDate(myUser);

But I get the following error:

System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.InvalidOperationException: There was an error generating the XML document. ---> System.InvalidOperationException: The type clsTicket was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically.

I Google the error and most of the answers I find have to do with serializing derived classes. But my clsTicket class is not a derived class. What can be causing this error? How do I use XmlInclude or SoapInclude?

Thanks in advance!

John Saunders
  • 160,644
  • 26
  • 247
  • 397
PaulG
  • 6,920
  • 12
  • 54
  • 98

3 Answers3

3

Okay I finally got it to work, I ended up putting the following line:

[XmlInclude(typeof(clsTicket))]

Between [WebMethod] and my method's definition. So far so good.

jrummell
  • 42,637
  • 17
  • 112
  • 171
PaulG
  • 6,920
  • 12
  • 54
  • 98
2

I don't think you need to 'new' result:

ServiceReference1.GetAllTicketsSinceLastPullDateResult result;
result = myClient.getAllTicketsSinceLastPullDate(myUser);

Also, how do you know the error isn't on the server? Can you call the function with a web browser?

Steve Wellens
  • 20,506
  • 2
  • 28
  • 69
  • I tried this through my web browser and I actually get the same error message. So it's probably server. Still not sure how to handle this though. – PaulG Jan 12 '12 at 15:46
1

Have you updated your service since initially adding the reference to your project? If you're using Visual Studio's "Add Web Reference" feature and you update the service, often times there is a configuration or parameter chance, which can generate SOAP errors.

Try right clicking on the Web Service in question through visual studio and select "Update" option. Recompile the app and see if that resolves your issue.

Dillie-O
  • 29,277
  • 14
  • 101
  • 140