Monthly Archives: August 2006

Calling Remote WebServices with custom objects

Have you ever tried to call a WebService and have it return a Custom Object (which both the server and the client have definitions for – e.g. in a shared project) and gotten an error message like:

  • C:\projects\…\WebServiceTests.cs(124): Cannot implicitly convert type ‘CreditSights.SalesLogix.WebService.Tests.WebService.User’ to ‘CreditSights.SalesLogix.TransportLayer.User’

Solution: Show all files, edit Reference.cs under the webservice, add “using;“, remove any created objects at the end of the definition (after the System.Web.Services.Protocols.SoapHttpClientProtocol class declaration)

Isn’t it annoying? Well, the issue is that when you create a webservice, Visual Studio.Net assumes that you don’t have any definitions of the remote objects (as would be the case when you are calling a webservice owned by someone else). So it creates proxy objects for the “custom” objects on the server. However, since you already have definitions for these objects, you probably don’t want to use their definitions. So, you just need to tell the object generated to use the shared namespace, and remove the generated objects – voila, it all works (you need to do this every time you refresh the webservice)

Caveat: Make sure you implement ISerializable, and only need the public members of the object.