Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Services / March 2007

Tip: Looking for answers? Try searching our database.

passing custom object to webservice

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Greger - 20 Sep 2006 09:39 GMT
Hi,

I am building an architecture that passes my custom objects to and from
webservices. (Our internal architecture requires me to use webservices to any
suggestion to use other remoting techniques are not feasible)

The question is;

Given that I have a Person object with a private set for id.
What is the recommended approac in passing that object to the web service
and still retain the value of id?

Getting the object from the webservice is no problem since I only use the
generated proxy class to achieve this.

Should I create a PersonData with public properties that I pass up to the
webservice or is there any other way?
This could be tricky since if the person object have a list och subitems the
PersonData would need that aswell creating a lot of code doing the same
thing...

I can not use interface because the webservice can not serialize that.

Any pointers to design guidelines or similar is appreciated.
(WCF is not an option right now)

Thanks in advance!

Regards Greger

Signature

----

Sundar Narasimman - 20 Sep 2006 11:41 GMT
Greger,

It's a good question. You can pass Custom objects to and from Web Services.
In your case , the Person Object, should have Public Properties to depitct
the details of the Person Object

As long as the properties of the Person object are a primitive types, you
don't have to bother too much. Look at the sample below ...

Public Class Person
    Public Property PersonId as Integer
   Public Property PersonName as String
End Class

If atleast one of the Property of the Person object is a CusomCollection,
you need to consider lot of things before passing objects to and from web
services.
The following scenario has address collection inside Person Object

Public Class Person
    Public Property PersonId as Integer
    Public Property PersonName as String
   Public  Propery PersonAddress as AddressCollection
End Class

In such case the Custom Collections are not transmitted directly between web
services and clients. Meaning Custom Collections are passed as Array of
Objecs.
If if it is passed as Array of Objects, you loose tight coupling between
Person Object and AddressCollection property. In this scenario you really
need to figure out a way to maintain the tight coupling between Person Object
and AddressCollection Propery.
         The way to do is to enable tight coupling with PersonId. Meaning
have a defintion for PersonId in the AddressCollection.

Please let me know if this reply is useful. If you need more information let
me know.
-
Thanks & Regards,
Sundar Narasimman

> Hi,
>
[quoted text clipped - 25 lines]
>
> Regards Greger
Greger - 20 Sep 2006 11:56 GMT
Hi Sundar,

Thanxs for the reply.
The gist of the question is when I send the proxy object to the server and
the server tries to recreate my object. It wont be able to set the,
intentionally, private set property. Leaving my object without essential data.

How can I have the framework deserialize my object correctly even though it
has a pricate set?

Regards Greger

Signature

----

> Greger,
>
[quoted text clipped - 66 lines]
> >
> > Regards Greger
Sundar Narasimman - 21 Sep 2006 12:35 GMT
Hi Greger,

Niow I can understand your problem better.
There is a way to do that. You can have a Public method in the Remote Object
to update the private property/member of the class.

Your remote Person object can have public and private properties/method.
As you know only Public properties/methods would be serialized back and
forth between Web Services and the Client. Meaning at the client-side, the
proxy will reflect only Public Properties/Methods of the remote object.

You can still call the Public method of the proxy, that inturn will get
executed at the server-side to update your private property/member.

This is really possible.

Pls let me know whether this is useful or you need more information
regarding this
Signature

Thanks & Regards,
Sundar Narasimman
Technology Specialist
Microsoft .NET

> Hi Sundar,
>
[quoted text clipped - 78 lines]
> > >
> > > Regards Greger
Ben Joyce - 21 Sep 2006 09:31 GMT
Wow, I didn't even know this was possible... so, you can serialize
custom classes in .net and send them over the web?  I am understanding
this right?

Ben

> Greger,
>
[quoted text clipped - 66 lines]
> >
> > Regards Greger
Sundar Narasimman - 21 Sep 2006 12:29 GMT
Hi Ben,

Yes you are right. You can serialize custom objects over the web . You can
even serialize custom object collections.

Thanks & Regards,
Sundar

> Wow, I didn't even know this was possible... so, you can serialize
> custom classes in .net and send them over the web?  I am understanding
[quoted text clipped - 72 lines]
> > >
> > > Regards Greger
Prerak V. Shah - 27 Feb 2007 21:48 GMT
Hi,

Your information is quite useful and I have one more question to it.

I am having one custom object which I accept as a parameter of my webmethod.
This object is getting generated in my proxy class of the webservice at the
consumer-end.

Now, I am not getting any of my public methods of my custom object in
generated proxy class. I am not getting even constructors.

Actually I am having one private variable of the type "object" in my custom
class "WebResponse". Depending on the type of the value it contains, I am
having public methods to return it's value. but I am not getting any of these
public methods in the proxy class.

Is there any way out here!

Thanks,
Prerak

> Hi Ben,
>
[quoted text clipped - 80 lines]
> > > >
> > > > Regards Greger
Mariano Omar Rodriguez - 07 Mar 2007 21:14 GMT
Custom objects are serialized with XmlSerializer, it only transport public
properties.

> Hi,
>
[quoted text clipped - 126 lines]
>> > > >
>> > > > Regards Greger

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.