How to pass custom object to WebMethod?

Want to pass my Currency entity object to a webmethod.  I have marked the object as Serializable.  However, another object with the same class name Currency(generated by VS.NET 2005) is required when I try to use the webmethod.  Why   How can I pass my entity object

Thanks




Answer this question

How to pass custom object to WebMethod?

  • HedleySohn

    Remember that using Web Services does not guaranty type identoty, in fact any type that can serialize to the same XML can be used in the client and the server.

    If you create a class that can be serializable and creating the proxy in the client by XSD.EXE, WSEWSDL_.EXE or VS.NET you will be able to pass your objects.



  • Domenico Barile

    I am using VS.NET.  I don't know why when I add web reference, a class with the same name "Currency"(but with different name space) is generated in the .WSDL file which replaced my original entity class as the method's parameter. When I compile, an error saying that cannot convert between the two "Currency" classes.  Why a new one is generated   How to deal with this
    Thanks a lot.


  • Paul Nolan

    Thanks for your help.
    But I wonder why this have to be done manually each time as web reference will be updated frequency during development.  Is there anywhere to specify reference of the Currency class to wsdl.exe

  • Divyachandra

    You can also use the XmlInclude attribute to specify the type that you want to use instead of the generated one.

    Daniel Roth



  • AshishKSrivastava

    New Currency class generated because wsdl.exe used for code generation have no knowledge (by design) about your Currency classes.

    To resolve problem with two Currency classes you may click "Show All Files" button on top of Solution Explorer and find file with generated code under Web References. Remove generated Currency class. After that you can add to this file "using" for namespace where original Currency class defined.
    Remember, if you update web reference your changes will be lost.


  • How to pass custom object to WebMethod?