Returning nested class from web service

Discussion in 'ASP .Net Web Services' started by Toby Mathews, Oct 28, 2003.

  1. Toby Mathews

    Toby Mathews Guest

    I have a class that I return from a web service. The client receives this
    fine and I can access all its properties and methods. However, the class
    also contains an instance of another class. The client can see the
    properties of this second class, but not the methods - does anyone know why
    this would be?

    I call a web method that returns an instance of the Test class (below), say
    called objTest in the web service client. If so I can get at
    objTest.Sub.Property ok, but not objTest.Sub.Method(). The latter does not
    appear in the available properties/methods displayed by intellisense in the
    Visual Studio IDE for example.

    public class Test
    {
    public Test()
    {
    }

    private MyNamespace.SubTest objSub = new MyNamespace.Subtest();
    public MyNamespace.SubTest Sub {get {return objSub;}}
    }

    public class SubTest
    {
    public SubTest()
    {
    {

    public string Property {get {return msProp;} set{msProp = value;}}

    public void Method(string Arg)
    {
    // Do something here.
    }
    }

    Any help would be much appreciated, thanks a lot,

    Toby Mathews
     
    Toby Mathews, Oct 28, 2003
    #1
    1. Advertising

  2. You cannot implicitly ship code with webservices.

    Suppose your server returns an instance of a complex type. If that type is
    known to the client - in other words if an assembly on the client side
    defines such a type - then the client will instantiate that type, and you
    will have access to all the behavior (methods) defined in that assembly.
    You need to specify targetNameSpace on the returned type to get this to
    work. See this article [1] for more.

    If the type is not known at the client, then at the time you create your
    proxy (running wsdl.exe or "add Web Reference" in VS), you will generate a
    Value Object type, which includes fields that map to the data members of the
    returned type. No methods.

    -Dino


    [1]
    http://msdn.microsoft.com/library/en-us/dnservice/html/service07162002.asp



    "Toby Mathews" <> wrote in message
    news:...
    > I have a class that I return from a web service. The client receives this
    > fine and I can access all its properties and methods. However, the class
    > also contains an instance of another class. The client can see the
    > properties of this second class, but not the methods - does anyone know

    why
    > this would be?
    >
    > I call a web method that returns an instance of the Test class (below),

    say
    > called objTest in the web service client. If so I can get at
    > objTest.Sub.Property ok, but not objTest.Sub.Method(). The latter does not
    > appear in the available properties/methods displayed by intellisense in

    the
    > Visual Studio IDE for example.
    >
    > public class Test
    > {
    > public Test()
    > {
    > }
    >
    > private MyNamespace.SubTest objSub = new MyNamespace.Subtest();
    > public MyNamespace.SubTest Sub {get {return objSub;}}
    > }
    >
    > public class SubTest
    > {
    > public SubTest()
    > {
    > {
    >
    > public string Property {get {return msProp;} set{msProp = value;}}
    >
    > public void Method(string Arg)
    > {
    > // Do something here.
    > }
    > }
    >
    > Any help would be much appreciated, thanks a lot,
    >
    > Toby Mathews
    >
    >
     
    Dino Chiesa [Microsoft], Oct 28, 2003
    #2
    1. Advertising

  3. Toby Mathews

    Mohan Guest

    Hi,
    i am repeating the message that i had posted for Expose
    methods of class returned.
    What you're trying to achieve is workable; but the best
    practise is not to have business functionality in the
    object that you're receiving, rather it has to be like a
    container.
    These will avoid having the proxy class as dll and client
    just access the web services and make use of it
    immediately rather than waiting for the dll from the
    server to be sent before in order to use the web service,
    this breaks the web service concept.
    Have a look at this it might help you.
    http://msdn.microsoft.com/msdnmag/issues/02/12/WebServicesD
    esign/

    When you look at the wsdl you should know what to be used
    and you write the functionality to use them.

    cheers.

    >-----Original Message-----
    >I have a class that I return from a web service. The

    client receives this
    >fine and I can access all its properties and methods.

    However, the class
    >also contains an instance of another class. The client

    can see the
    >properties of this second class, but not the methods -

    does anyone know why
    >this would be?
    >
    >I call a web method that returns an instance of the Test

    class (below), say
    >called objTest in the web service client. If so I can get

    at
    >objTest.Sub.Property ok, but not objTest.Sub.Method().

    The latter does not
    >appear in the available properties/methods displayed by

    intellisense in the
    >Visual Studio IDE for example.
    >
    >public class Test
    >{
    > public Test()
    > {
    > }
    >
    > private MyNamespace.SubTest objSub = new

    MyNamespace.Subtest();
    > public MyNamespace.SubTest Sub {get {return objSub;}}
    >}
    >
    >public class SubTest
    >{
    > public SubTest()
    > {
    > {
    >
    > public string Property {get {return msProp;} set

    {msProp = value;}}
    >
    > public void Method(string Arg)
    > {
    > // Do something here.
    > }
    >}
    >
    >Any help would be much appreciated, thanks a lot,
    >
    >Toby Mathews
    >
    >
    >.
    >
     
    Mohan, Nov 4, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page