• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 388
  • Last Modified:

Inherited class not published through a WebService's WSDL

I have a web-service with a web-method that returns a (simple) object of type TestBase, and when I create a TestBase object and return it everything works OK,
if I create a TestChild class that inherits from TestBase, it is not exposed in the WebService's WSDL (since the WebMethod is of return-type TestBase), and the object returned from the method of type TestBase is not recoginzed, I get an InvalidOperationException telling serializer does not know how to serialize this object,
If I create another (web)method of type TestChild, then the first method (that is defined returning a TestBase) works well, since the TestChild's class interface is published through the WSDL, and is also shown in Object Browser when updating the web-reference.

So, I think what I need is simply a way of exposing TestChild's interface through the TestService's WSDL without having to explicitly create a TestChild web-method.

1 Solution
what I can suggest you is that let the method have return-type as TestBase. Along with this you need to set a WebMethodAttribute above your webmethod which should include type of class TestChild so that it gets defined in the WSDL. It can be done as follows:

public TestBase WebMethodName()
After this build the project and update the webreference in your client appl.
Then when you will get the TestChild class in your Client appl by typing namespace.TestChild


Chirag Patel.
zivfAuthor Commented:
I had this attribute suggested from the exception I got, but I probably tried adding it to whereever I could other than that specific place. The most suitable place for it semed to me to be the class-level, so adding it to the method did solve the proble.

Thanks a lot, you save me a lot of time and a lot of unnecessary programming....


Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now