Passing a "custom object" to a webservice?

H

hellrazor

Hi there,

I'm very new to dot net programming and webservices programming. I've
managed to create simple webservices so far.

Here's my problem:

-I've been given a project which needs to have a proprietary algorithm
split into a webservice.

-The program consuming the webservice needs to send a custom class object,
"Stroke" to the webservice, which will be located in a different computer.

-The webservice needs to have access to a couple of the "Stroke" members,
run some algorithms, and modify a member of the Stroke instance. The
modified Stroke instance needs to be sent back to the "Client" (the
consumer)


-The custom class seems to be serialized in the client:

[Serializable] public class Stroke { .... }


Question:

-How do I let the webservice project know about Stroke? The class template
in the client is quite large


Thanks!

Jorge
 
N

Nicholas Paldino [.NET/C# MVP]

Jorge,

You actually don't have to do much. You just have to make sure that
your type works with XmlSerialization. XmlSerialization isn't the same as
normal serialization. XmlSerialization works by getting all of the
publically available values from the class (public fields and properties)
and sends those.

If your class can expose its state through only publically available
members, then you should be fine (assuming they are not read only).

Once you do that, you just have to expose your method, and when you
generate a proxy, the type information for Stroke will be exposed through
the WSDL, which will be exposed in the client-side proxy that will be used.

Hope this helps.
 
R

Richard Blewett [DevelopMentor]

You cannot send an object to a webservice. Webservice's receive messages (data in other words) not behaviour. Therefore, you can send the state of the stroke but you can't send the methods. Those will have to coded at the webservice, or it will need access to the stroke type (via its assembly) on the server and use the state passed to instantiate a new stroke object that has the methods.

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/<[email protected]>

Hi there,

I'm very new to dot net programming and webservices programming. I've
managed to create simple webservices so far.

Here's my problem:

-I've been given a project which needs to have a proprietary algorithm
split into a webservice.

-The program consuming the webservice needs to send a custom class object,
"Stroke" to the webservice, which will be located in a different computer.

-The webservice needs to have access to a couple of the "Stroke" members,
run some algorithms, and modify a member of the Stroke instance. The
modified Stroke instance needs to be sent back to the "Client" (the
consumer)
 
M

MattC

If the class is part of an assembly that is available to both webservice and
client can the object be reformed in the webservice using the serialized
data?

MattC

Richard Blewett said:
You cannot send an object to a webservice. Webservice's receive messages
(data in other words) not behaviour. Therefore, you can send the state of
the stroke but you can't send the methods. Those will have to coded at the
webservice, or it will need access to the stroke type (via its assembly) on
the server and use the state passed to instantiate a new stroke object that
has the methods.
 

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

Top