Search code examples
c#web-servicespocoauto-generate

C#: Webservice changes expected parameter type (from a normal POCO to a an autogenerated class)


I have the following class in Class Library: Artist, which is a POCO

Now I have a method in a web-service (which has a reference to the mentioned-above library) with a signature like this:

[WebMethod]
public int Artist_AddArtist(Artist a) {
 //
}

When I try to consume this service from an application (that also has a reference to the mentioned-above Class library), the expected parameter of the Artist_AddArtist method is not Artist, but a new type of Artist that is being generated in Reference.cs which is a partial class that is auto-generated.

Thus since in my application I use, supposedly the same Artist class from the library and now the Web Service method expects this new auto generated type, I cannot pass an instance of it to the web-service.

How can I fix this issue?


Solution

  • Maybe switching to WCF services is an option for you. As far as I remember, with a WCF service, you can reuse the same types on ther server and client side.

    This article explains how to migrate an ASMX web service to a WCF service.