Use custom objects

Last post 05-15-2008 12:10 PM by vishalbade. 5 replies.

Sort Posts:

  • Use custom objects

    05-15-2008, 8:28 AM
    • Loading...
    • JontyMC
    • Joined on 05-17-2006, 4:05 PM
    • Posts 100

    When consuming a web service, visual studio creates a proxy class with its own objects eg WebService.Customer. My application already has a set of its own objects, whats the best way to have the web service return my applications objects, eg MyApplication.Customer?

    I am using Visual Studio 2008 and C# 3.5.
     

  • Re: Use custom objects

    05-15-2008, 9:40 AM

    Example: If your web service has a Video public class, your proxy in client app will also contain the definition for Video class. In your client code, you should create an object of the Video class using the proxy and not from any place else.

    Let me know If I misunderstood your question.

    Vishal
  • Re: Use custom objects

    05-15-2008, 9:53 AM
    • Loading...
    • JontyMC
    • Joined on 05-17-2006, 4:05 PM
    • Posts 100

    I don't want to use the proxy class, I want to use the class I have already declared. Is there a standard way to map the proxy class to my custom class?

    On a separate issue (I cannot use the classes from the web service at the moment) - what about the situation where I am creating the web service, how can I use the class on the web service and get the same object type back on the client (using the same class library)?

  • Re: Use custom objects

    05-15-2008, 10:48 AM

    I dont think that is possible. As you know lot of ground work is done in the background when calling web methods. SOAP Request, SOAP response are created for you. Also the types, parameters in both request and response have to be serialized and de serialized so that we exchange info over the wire/network. If you dont use the proxy this will defeat the whole purpose. This is as per my knowledge.

    I have tried using VS 2005, .NET 2.0, as follows. You could have a common class library with your custom objects. use this library in both web service and the client app. when you use the objects local to the client app you would get an conversion error

    ClassLibrary CommonClassLib holding the custom objects
    public class Video
    {
            public string strTitle;
            public ArrayList arrProducer = new ArrayList();
    }

    Proxy generated "Video" object has the following attributes attached. [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "2.0.50727.42")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(Namespace="http://www.bostonVideo.com/ComplexTypeService")]
    public partial class Video {
    ...
    }

    You woud get an conversion error as follows
    Cannot implicitly convert type 'ConsoleApplication2.localhost.Video' to 'CommonClassLib.Video' 

    Hope this helps.

    Vishal
  • Re: Use custom objects

    05-15-2008, 11:52 AM
    • Loading...
    • JontyMC
    • Joined on 05-17-2006, 4:05 PM
    • Posts 100

    I can see how it you would require some mapping if the client class library used was not the same as the web service class library. I'll simply have to create a wrapper that copies properties to the custom object from the proxy object.

    What about the case where the web service and client both use the same class library. Surely there is some easy way to de-serialize back to the original type?
     

  • Re: Use custom objects

    05-15-2008, 12:10 PM
    Answer

    The sample which I tested uses the same classlibrary dll across client and Web service. But still you get the conversion error.

    But I do get your point. If you want to send a custom object as a parameter to web method call and you already have a filled in custom object, why would you create an object using the proxy set individual values right. You might have to come up with a way to copy contents of the local custom object to that of the proxy custom object in this case.

    Sorry I will not be able to assist further on this.

    Vishal
Page 1 of 1 (6 items)