How to use own classes as WebMethod-Parameters?

D

Daniel Barisch

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
 
S

Simon Smith

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

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top