Inherited class not published through a WebService's WSDL

Posted on 2007-08-02
Last Modified: 2012-06-21
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.

Question by:zivf
    LVL 9

    Accepted 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.
    LVL 1

    Author Comment

    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

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    Suggested Solutions

    Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now