How to use own classes as WebMethod-Parameters?

Ask a Question related to ASP.NET Web Services, Design and Development.

  1. #1

    Default How to use own classes as WebMethod-Parameters?

    Is it possible to use self defined classes as parameters for a WebMethod? I
    thought of the following....

    1. Library-Project: "LibProj"

    Public Class ParamClass
    private ...
    public ...
    public sub addXY...
    End Class

    2. WebService-Project: "WSProj"
    (Reference to "LibProj")

    <WebService>
    Public Class WServer
    <WebMethod> _
    Public function getSth( param as LibProj.ParamClass)....
    end class

    3. Client-Project: "ClientProj"
    (Reference to "LibProj", WebReference to "WSProj" as "WSProjProxy")

    public sub doSth
    dim ws as new WSProjProxy.WServer()
    dim pc as new LibProj.ParamClass()
    msgbox ws.getSth( pc ) >> ERROR (Parameter "pc")
    end sub


    This does not work, because " 'LibProj.ParamClass' can't be converted to
    'ClientProj.WSProjProxy.ParamClass' "

    What is wrong with this code? Why suddenly the type of the
    WebService-parameter switches from 'LibProj.ParamClass' (as defined in the
    WebMethod) to 'WSProjProxy.ParamClass'?

    Is there possibility to get this work?

    Thanks, D.Barisch


    Daniel Barisch Guest

  2. Similar Questions and Discussions

    1. Mandatory WebMethod parameters
      Hi, I have WebService (C#) with one WebMethod that takes 4 parameters, as below: <s:element minOccurs="0" maxOccurs="1" name="requestedBy"...
    2. WebMethod and WSDL with optional parameters
      Hi If i have a simple web service lik [WebMethodAttribute() public string DoIt(string Name, int Age return "" and i look at the WSDL i get...
    3. Carriage Return in WebMethod parameters
      Hi! I have this problem. I am sending as a parameter for a webmethod a string containing '\r\n' sequences. For some reason, when I debug my...
    4. create parameters without creating parameters
      cant you create ado command parameteres without creating a parameter object? i have a function that takes the name of a stored proc, and two...
    5. exposing derived classes to proxy without fake webmethod?
      Hi, try using on the appropriate WebMethod. This attribute instructs the ASMX engine to include the type description for type bla. Cheers, --...
  3. #2

    Default Re: How to use own classes as WebMethod-Parameters?

    "Daniel Barisch" <goblin.inc@gmx.de> wrote in message news:<#cLHo5lZDHA.1644@TK2MSFTNGP10.phx.gbl>...
    > Is it possible to use self defined classes as parameters for a WebMethod? I
    > thought of the following....
    >
    <snip>
    > This does not work, because " 'LibProj.ParamClass' can't be converted to
    > 'ClientProj.WSProjProxy.ParamClass' "
    >
    > What is wrong with this code? Why suddenly the type of the
    > WebService-parameter switches from 'LibProj.ParamClass' (as defined in the
    > WebMethod) to 'WSProjProxy.ParamClass'?
    >
    > Is there possibility to get this work?
    >
    > Thanks, D.Barisch
    You're almost there. The Web Reference in the client has the code in a
    file called Reference.cs - this is the proxy for the Web Service. In
    that file is a definition of what your custom class looks like when
    deserialised - all properties etc as public fields. This is the class
    called WSProjProxy.ParamClass. Whjat you need to do is delete that
    class and add a using LibProj to theis file. That will tell the
    compiler to deserialise to you your custom class in LibProj, not the
    'stub' generated.

    HTH.
    Simon Smith Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139