Passing objects to web methods

C

Chris Dunaway

Fairly new to web services so bear with me.

I have a simple class library with the following class:

Public Class SimpleClass
Private _AnInteger As Integer
Private _AString As String

Public Property AnInteger() As Integer
Get
Return _AnInteger
End Get
Set(ByVal Value As Integer)
_AnInteger = Value
End Set
End Property

Public Property AString() As String
Get
Return _AString
End Get
Set(ByVal Value As String)
_AString = Value
End Set
End Property

End Class

This is compiled into a .dll

I have a web service that references the .dll with web methods declared
thusly:

<WebMethod()> _
Public Function SomeMethod() As SimpleClass
Dim sc as new SimpleClass

sc.AnInteger = 1
sc.AString = "One"
End Function

<WebMethod()> _
Public Sub AnotherMethod(ByVal sc As SimpleClass)
Dim sc2 as SimpleClass = sc

sc2.AnInteger = 2
sc2.AString = "Two"
End Sub


Nothing too complex about this so far.

Finally I have a Windows Forms Application that consumes the web service.

Dim ws as New localhost.WebService

this windows app also references the SimpleClass class library .dll


What I want to be able to do is something like this:

Dim oMySimpleClassInstance As SimpleClass = ws.SomeMethod()

ws.AnotherMethod(oMySimpleClassInstance)


But I can't do this. I have to declare the object as
localhost.SimpleClass. So if I want to work with a SimpleClass instance
from the class library, I have to use code like this:

Dim oMySimpleClassInstance As New SimpleClass
Dim oWebServiceSimpleClass As localhost.SimpleClass = ws.SomeMethod()

oMySimpleClassInstance.AnInteger = oWebServiceSimpleClass.AnInteger
oMySimpleClassInstance.AString = oWebServiceSimpleClass.AString

And I have to do the opposite when calling the ws.AnotherMethod.


Bottom line, All I want to do is create an object on the client side and
pass that object to the web service without having to manually convert it
back and forth to the proxy class! The classes I intend to use will only
have basic data types (strings, integers, etc). They might have an array
variable, but the array will only hold basic datatypes.

I'm sure there must be something I'm not getting. Do I need to serialize
the object and just pass a byte array to the web service?

Any help is appreciated.

Chris

P.S. Sorry for the long post
 
R

richlm

Chris

I find it useful to think of web services as more of a message based
protocol than an RPC based protocol.
You send a request; you get back a response - much like web pages.

If you think of it that way, it's easier to see that serializing "complex"
types to binary or XML is an appropriate approach.

You CAN do this with remoting, and for example define an interface in VB/C#
used by both client and server.
The "interface" language for web services is of course WSDL, which has no
way of expressing a direct relationship to a .NET class.

Hope this makes it clearer.

Richard.
 
C

Chris Dunaway

I find it useful to think of web services as more of a message based
protocol than an RPC based protocol.
You send a request; you get back a response - much like web pages.

Thanks for the response. I resolved my problem by editing the proxy class
to use my own custom objects. That seemed to work fine. The only glitch
is that if I update the web service through the IDE, I will have to re-edit
the proxy class. But since it is so little code to change, it is
convenient for me.

Thanks again.
 

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,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top