Returning nested class from web service

T

Toby Mathews

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
 
D

Dino Chiesa [Microsoft]

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
 
M

Mohan

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top