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.

Who is Participating?
Chirag1211Connect With a Mentor Commented:
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....

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.