Passing custom objects between webservices

Results 1 to 6 of 6

Thread: Passing custom objects between webservices

  1. #1
    Join Date
    Dec 1969

    Default Passing custom objects between webservices

    &nbsp;<BR>the same object type as a parameter. <BR><BR>CustomObject = Webservice1.Function1(param1, param2, param3)<BR>Webservice2.Function2(CustomObject)<BR> <BR>The CustomObject is defined in a class library, and both web services <BR>reference that library when typing the variable.<BR><BR>Even though the objects "should" be the same, I am getting a "can not <BR>convert" error, and if I try to cast the object myself it says invalid cast.<BR><BR>Please Advice!

  2. #2
    Join Date
    Dec 1969

    Default Yep...true statement!

    The serialized object that your client sees coming from the web service only *LOOKS* like the original object. But it is in a different namespace (specifically, the web service&#039;s namespace) and has none of the methods and user-defined properties of your custom class.<BR><BR>The best solution is to provide a constructor for your custom class that will take one of the web service objects as an argument and do member-wise copy.<BR><BR>This same problem exists when using typed datasets. And the (somewhat ugly) solution there is to use the DataTable.Merge method, as even on a typed dataset it will take an untyped dataset (okay, actually datatable) as an argument.<BR><BR>I&#039;ve never tried it, but if you use VB.NET and *PURPOSELY* do NOT use Option Explicit, then you *may* be able to get the cast to work. Not sure exactly how CTYPE works in such a situation.<BR><BR>

  3. #3

    Default RE: Yep...true statement!

    Isn&#039;t the best thing to distibute a assembly that contains the class and to reference the class from that assembly instead of the one in the proxy?<BR>I don&#039;t think it is a good plan to make the "real" class responsible for understanding web service object...maybe an adapter of some kind, or just a method in the web service&#039;s code?<BR><BR>If the object you will return from the service is serializable, you should be able to create an instance by deserializing the (xml from serializing a ) proxy version. This uses the default constructor and public settable properties (property-wise copy), so things may get lost.<BR><BR>I will remember that Merge trick ;)<BR><BR>

  4. #4
    Join Date
    Dec 1969

    Default Yes, but...

    ...if you use the default proxy that Visual Studio generates for you, it *will* be a proxy that returns a "constructed" version of what the service presents via its .disco (or wsdl? I forget) information.<BR><BR>Sure, you could construct your own proxy that uses ReadXML to fill an instance of your assembly/library class. Just that&#039;s beyond many newbies.<BR><BR>I&#039;m not sure what the "right" solution is. Ideally, you&#039;d like to see the proxy generator be able to handle it for you. Maybe you tell it to *try* to convert the .disco info into an instance of a class in a library you hand it? There&#039;s no reason the framework can&#039;t handle this, but you just need a tool to create the right proxy.<BR><BR>At least, that&#039;s where my understanding of things stands right now.<BR><BR><BR><BR><BR>

  5. #5

    Default WebServices disconnect ;)

    I keep wondering if we are talking about the same thing :)<BR><BR>...if you have one method that returns an object of type RemoteInfo an annother that accept RemoteInfo as a parameter.<BR><BR>If the consumer of the web service is annother solution that uses a web reference, he can create an instance of the RemoteInfo proxy and pass it to the method that accepts the real RemoteInfo.<BR><BR>Im doing this regularly using classes that are desiged for use in web services; data objects with helpful constructors.<BR><BR>I dug up and used this today :<BR> stopic.asp<BR><BR><BR><BR>I posted an example:<BR><BR>

  6. #6

    Default Are you there Bill? RE: WebServices disconnect ;)

    I would really like your views on this.<BR>I might be doing bad things...<BR><BR>:D

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts