Passing objects with web services

F

Family Tree Mike

ThatsIT.net.au said:
That's how I have done it, I'm using vb, but yes I Have the Reference.vb
file and I can see PublicUser in it, I also have a PublicUser.data file

But I still don't have the methods or properties

Jeff and Mr. Arnold have tried to explain that what is passed back is an
object with a class template resembling the SERVER SIDE class
PublicUser. It (the template) does not containg code behind the class.
In other words, if you make a local change such as
PublicUserObj.PhoneNumber = "703-555-1212", then if the server code
would have done some validations, they are not done on the client. The
client will not have the code to do the validations.

To get done what you want, you will need the client to have a full
definition of the class.
 
T

ThatsIT.net.au

Peter K said:
ThatsIT.net.au said:
Peter K said:
"Mr. Arnold" <MR. (e-mail address removed)> skrev i en meddelelse

I have a object that I want to pass back though a web service to the
consumer. when I do this i get the object but can not see any methods.
the object is decleared in the webservice as PublicUser, in the
consuming web site PublicUser comes up in intellisence so i know that
it must be comming though ok, but I can not access its methods.

When you pass an object like that back from the Web service, the
methods are left behind, and you only have access to public properties
of the object on the client side.

You have to serialize the object on the Web service side and pass back
an XML serialized object to the client.

But aren't the details of this normally handled by code automatically
generated by Visual Studio for example?

(I've only had to manually serialise some data in a WCF service we were
developing for .net <-> .net applications).

At least as far as simple web-services go, I've let VS handle all the
hard stuff for me.


You have to deserialize the XML serialize object and cast it back to
PublicUser on the client side. You will then have the data in the
PublicUser, and you can then access any public properties and methods
of the object at that time, on the client side.

Again, it appears to me that Visual Studio automatically generates the
code that handles this. Doesn't it? I'd be the first to admit I could be
completely wrong, and have just been incredibly lucky with the few
simple web-services I've written over the last few years - but for me,
at least, I've let Visual Studio do all this, and I simply call the
generated proxy and use the "PublicUser" object.

it looks that way to me in the code in Reference.vb

<System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml",
"2.0.50727.4016"), _
System.SerializableAttribute(), _
System.Diagnostics.DebuggerStepThroughAttribute(), _
System.ComponentModel.DesignerCategoryAttribute("code"), _
System.Xml.Serialization.XmlTypeAttribute([Namespace]:="http://blah
blah/WebUser")> _
Partial Public Class PublicUser
Inherits Person
End Class

Well it is obvious the PublicUser class has no properties or methods - and
it appears it descends from a class called Person. You need to ensure that
the Person class is also serialised so your client knows about it. Is
there a Person class in the Reference.vb code?


Yes, i also tried with a non inherted class with the same result.

<System.Xml.Serialization.XmlIncludeAttribute(GetType(PublicUser)), _
System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml",
"2.0.50727.4016"), _
System.SerializableAttribute(), _
System.Diagnostics.DebuggerStepThroughAttribute(), _
System.ComponentModel.DesignerCategoryAttribute("code"), _
System.Xml.Serialization.XmlTypeAttribute([Namespace]:="http://blah
blah/WebUser")> _
Partial Public MustInherit Class Person
End Class
 
T

ThatsIT.net.au

Family Tree Mike said:
Jeff and Mr. Arnold have tried to explain that what is passed back is an
object with a class template resembling the SERVER SIDE class PublicUser.
It (the template) does not containg code behind the class. In other words,
if you make a local change such as PublicUserObj.PhoneNumber =
"703-555-1212", then if the server code would have done some validations,
they are not done on the client. The client will not have the code to do
the validations.

To get done what you want, you will need the client to have a full
definition of the class.


yes but how?
I think what i was trying to do is n ot posible

What I can do, is just recreat the methods of the class in the WS, and then
just pass then on to the PublicUser object

but i was wondering if the WS had the power to pass a conected object. I
guess I qwas expecting too much.


Thanks
 
P

Peter K

Mr. Arnold said:
Peter K said:
But aren't the details of this normally handled by code automatically
generated by Visual Studio for example?


I don't think so without some help when dealing with objects of the type
the OP is posting about.
(I've only had to manually serialise some data in a WCF service we were
developing for .net <-> .net applications).

At least as far as simple web-services go, I've let VS handle all the
hard stuff for me.



Again, it appears to me that Visual Studio automatically generates the
code that handles this. Doesn't it? I'd be the first to admit I could be
completely wrong, and have just been incredibly lucky with the few simple
web-services I've written over the last few years - but for me, at least,
I've let Visual Studio do all this, and I simply call the generated proxy
and use the "PublicUser" object.

I don't think that it's going to generate the code by itself, without it
being told to do so based on the type of object the OP is posting about,
and even with a WCF Web Service, you have to decorate the class and
properties of the class with the [Serializable] attribute, becuase for
sure WCF expects it for an object it's sending or receiving, at the very
least [Serializable] be decorating the class.
I also always thought one couldn't actually send "methods" of a custom
object via a webservice. I thought it was only possible to send
"properties" (or data). I've really only had success with that anyway.
Guess I'll do a little more digging myself.

And may be that's OP's problem that the class he is trying to pass back is
not decorated with [Serializable] attributes, which is going to make it an
XML serialized object, which .Net will do it by itself, as I recall. I am
not sure, as I don't work with legacy ASP.NET Web services anymore only
ASP.NET WCF Web services.

He can just simple do the serialize and deserialize code himself too, but
the object in his case but be an XML serialized object.
http://www.codeproject.com/Articles/37824/Serializing-and-Deserializing-Objects-to-and-from-XML.aspx

Yeah - well, I won't try to guess any more, I'm not an expert and tend to
choose the simplest route I can. I'd actually recommend that the OP uses all
the automatic tools provided by Visual Studio he can, and return
ultra-simple objects which simply deliver data, instead of complex objects
which include all manner of methods, and what is starting to sound like
methods including some sort of remoting capabilities.

How does the custom serialisation affect the compatibility of the
web-service for example? Can my client connect to the webservice by using
the appropriate url (and wsdl)?

What does the WSDL look like, by the way?
 
T

ThatsIT.net.au

Peter K said:
Mr. Arnold said:
Peter K said:
"Mr. Arnold" <MR. (e-mail address removed)> skrev i en meddelelse

I have a object that I want to pass back though a web service to the
consumer. when I do this i get the object but can not see any methods.
the object is decleared in the webservice as PublicUser, in the
consuming web site PublicUser comes up in intellisence so i know that
it must be comming though ok, but I can not access its methods.

When you pass an object like that back from the Web service, the
methods are left behind, and you only have access to public properties
of the object on the client side.

You have to serialize the object on the Web service side and pass back
an XML serialized object to the client.

But aren't the details of this normally handled by code automatically
generated by Visual Studio for example?


I don't think so without some help when dealing with objects of the type
the OP is posting about.
(I've only had to manually serialise some data in a WCF service we were
developing for .net <-> .net applications).

At least as far as simple web-services go, I've let VS handle all the
hard stuff for me.


You have to deserialize the XML serialize object and cast it back to
PublicUser on the client side. You will then have the data in the
PublicUser, and you can then access any public properties and methods
of the object at that time, on the client side.

Again, it appears to me that Visual Studio automatically generates the
code that handles this. Doesn't it? I'd be the first to admit I could be
completely wrong, and have just been incredibly lucky with the few
simple web-services I've written over the last few years - but for me,
at least, I've let Visual Studio do all this, and I simply call the
generated proxy and use the "PublicUser" object.

I don't think that it's going to generate the code by itself, without it
being told to do so based on the type of object the OP is posting about,
and even with a WCF Web Service, you have to decorate the class and
properties of the class with the [Serializable] attribute, becuase for
sure WCF expects it for an object it's sending or receiving, at the very
least [Serializable] be decorating the class.
I also always thought one couldn't actually send "methods" of a custom
object via a webservice. I thought it was only possible to send
"properties" (or data). I've really only had success with that anyway.
Guess I'll do a little more digging myself.

And may be that's OP's problem that the class he is trying to pass back
is not decorated with [Serializable] attributes, which is going to make
it an XML serialized object, which .Net will do it by itself, as I
recall. I am not sure, as I don't work with legacy ASP.NET Web services
anymore only ASP.NET WCF Web services.

He can just simple do the serialize and deserialize code himself too, but
the object in his case but be an XML serialized object.
http://www.codeproject.com/Articles/37824/Serializing-and-Deserializing-Objects-to-and-from-XML.aspx

Yeah - well, I won't try to guess any more, I'm not an expert and tend to
choose the simplest route I can. I'd actually recommend that the OP uses
all the automatic tools provided by Visual Studio he can, and return
ultra-simple objects which simply deliver data, instead of complex objects
which include all manner of methods, and what is starting to sound like
methods including some sort of remoting capabilities.

Yes that is what i was trying to do, not so much that i need it, but to see
just what i could do with a WS

I have decided against, but i will want to pass some simple objects
(properties only) all the same as you metion above.
I will want to pass them back also
i'll give it a go in the morning.

Thank all
 
T

ThatsIT.net.au

Peter K said:
Mr. Arnold said:
Peter K said:
"Mr. Arnold" <MR. (e-mail address removed)> skrev i en meddelelse

I have a object that I want to pass back though a web service to the
consumer. when I do this i get the object but can not see any methods.
the object is decleared in the webservice as PublicUser, in the
consuming web site PublicUser comes up in intellisence so i know that
it must be comming though ok, but I can not access its methods.

When you pass an object like that back from the Web service, the
methods are left behind, and you only have access to public properties
of the object on the client side.

You have to serialize the object on the Web service side and pass back
an XML serialized object to the client.

But aren't the details of this normally handled by code automatically
generated by Visual Studio for example?


I don't think so without some help when dealing with objects of the type
the OP is posting about.
(I've only had to manually serialise some data in a WCF service we were
developing for .net <-> .net applications).

At least as far as simple web-services go, I've let VS handle all the
hard stuff for me.


You have to deserialize the XML serialize object and cast it back to
PublicUser on the client side. You will then have the data in the
PublicUser, and you can then access any public properties and methods
of the object at that time, on the client side.

Again, it appears to me that Visual Studio automatically generates the
code that handles this. Doesn't it? I'd be the first to admit I could be
completely wrong, and have just been incredibly lucky with the few
simple web-services I've written over the last few years - but for me,
at least, I've let Visual Studio do all this, and I simply call the
generated proxy and use the "PublicUser" object.

I don't think that it's going to generate the code by itself, without it
being told to do so based on the type of object the OP is posting about,
and even with a WCF Web Service, you have to decorate the class and
properties of the class with the [Serializable] attribute, becuase for
sure WCF expects it for an object it's sending or receiving, at the very
least [Serializable] be decorating the class.
I also always thought one couldn't actually send "methods" of a custom
object via a webservice. I thought it was only possible to send
"properties" (or data). I've really only had success with that anyway.
Guess I'll do a little more digging myself.

And may be that's OP's problem that the class he is trying to pass back
is not decorated with [Serializable] attributes, which is going to make
it an XML serialized object, which .Net will do it by itself, as I
recall. I am not sure, as I don't work with legacy ASP.NET Web services
anymore only ASP.NET WCF Web services.

He can just simple do the serialize and deserialize code himself too, but
the object in his case but be an XML serialized object.
http://www.codeproject.com/Articles/37824/Serializing-and-Deserializing-Objects-to-and-from-XML.aspx

Yeah - well, I won't try to guess any more, I'm not an expert and tend to
choose the simplest route I can. I'd actually recommend that the OP uses
all the automatic tools provided by Visual Studio he can, and return
ultra-simple objects which simply deliver data, instead of complex objects
which include all manner of methods, and what is starting to sound like
methods including some sort of remoting capabilities.

Yes that is what i was trying to do, not so much that i need it, but to see
just what i could do with a WS

I have decided against, but i will want to pass some simple objects
(properties only) all the same as you metion above.
I will want to pass them back also
i'll give it a go in the morning.

Thank all
 
F

Family Tree Mike

ThatsIT.net.au said:
yes but how?
I think what i was trying to do is n ot posible

What I can do, is just recreat the methods of the class in the WS, and
then just pass then on to the PublicUser object

but i was wondering if the WS had the power to pass a conected object.
I guess I qwas expecting too much.


Thanks

A way of doing this is to have three divisions of code 1) Server 2)
Client 3) Shared. The PublicUser class sounds like it would be put into
the Shared section of code. Think of this as three dlls. The client
has ClientLibrary.dll, and SharedLibrary.dll while the server has
ServerLibrary.dll and SharedLibrary.dll.

You then need to add code in your ClientLibrary that after the server
object is fetched, the properties returned are used to fill out a
SharedLibrary object.

Another approach is to open methods on the WS that execute the methods
on an object sent back, as you suggested. There are trade offs with
each method. Frequency of server hits, data consistency if this server
app is a data management system and data transfer times, to name a few.
 

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