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