OK,
You have a webservice, coded in ASMX. It exposes a few methods. The
methods accept various input params (of various types) and they return
outputs of various types.
You run wsdl.exe on the associated WSDL (interface definition), or
alternatively if you are using Visual Studio you "Add Web Reference...", to
generate a client proxy. The client proxy is a type that exposes methods,
one for each method in the WSDL. In other words, one for each [WebMethod]
in your ASMX.
Ok, still with me?
if you examine the generated client proxy code (by default it is C#, but you
can also ask for it to be generated in VB.NET), you will see type
definitions for all of the various inputs and outputs that are not simple
built-in types or arrays of same. In other words, if you have in your ASMX:
[Webmethod]
public MySpecialType Method1() {
}
where MySpecialType is defined in your server code somewhere, then in the
generate client proxy code you will get a new definition of MySpecialType in
the proxy code. It usually follows all the code for the proxy class. And
in the generated proxy class code for the given webmethod (Method1 in our
example), you will see the return value being cast to MySpecialType. It
will look like so:
object[] results= this.Invoke("Method1",...);
return ((MySpecialType)(results[0]));
Again, this is if you use the default language for proxy generation (C#).
So I don't understand what you mean when you say,
I can't create an object on the client to bind to this passed back object
It's already done for you in the proxy code, is it not?
=====
That's the basic stuff. Now on to the more complex stuff, see the "At Your
Service" columns in the MSDN library, online at:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnanchor/html/webservicesanchor.asp
They have columns that talk about interfaces and types and inherited types
and so on.
This one may be of interest to you:
http://msdn.microsoft.com/library/en-us/dnservice/html/service07162002.asp
-Dino
Jason B said:
Michael, thanks for the reply. You're right, the client cannot recreate the
object passed back from the webmethod. I can't create an object on the
client to bind to this passed back object because I cannot see the sub
classes in the client. The client ONLY sees the asmx base class - no other
classes. So at this point, passing back or inheriting from an abstract class
is moot because the client can't see the classes to begin with.
I'm guessing that .Net webservices are not setup this way. You can use
derived classes within the web service, but they cannot be exposed to a
client. I'm thinking at this point that you have a 1 to 1 relationship
between an asmx web service and the class visible to the client.
I actually tried Jan's idea before she suggested it and didn't come up with
a way to get the sub class object back to the client. The client just
doesn't know anything about that sub class... If you run the web service
through the IDE (VS), you get a list of methods for base class service. It
doesn't expose any other classes you have subsequently added.
I'm kind of new to distributed computing and .Net in general, so I'm not
sure I'm not missing something still. Maybe I'm overlooking something
obvious?
Jason
approach.
I'll
and
I
wasn't able to use any properties and methods of the object anyway.
Am I missing something in between the lines? It's not the webservice I'm
having the problem in, it's in object instantiation in the client.
Thanks again,
Jason
I use this kind of constructions all the time! It's an
implementation
of
the
Factory Design Pattern.
--
Greetz
Jan Tielens
________________________________
Read my weblog:
http://weblogs.asp.net/jan
Jan, have you actually implemented a solution that way? I did that
exact
same thing with:
[WebMethod]
public Product GetProductObj() {
Product test = new Product("test");
test.Name = "testname";
return test;
}
The problem that I ran into was that the client is not able to create
an
object type that accepts the function return. Late binding
didn't
work
in
the single instance I tried either. That's why I'm asking if you've
implemented this before? It's one thing to post an idea, another if
you've
actually made it work.
Your help is appreciated,
Jason
You should create a webmethod that returns (or accepts as a
parameter)
an
instance of the Customer class:
public class ProductSupport : System.Web.Services.WebService {
public Customer GetCustomer()
{
Customer mycust = New Customer(...);
return mycust;
}
}
public class Customer
{
public string Name
{
//...
}
}
--
Greetz
Jan Tielens
________________________________
Read my weblog:
http://weblogs.asp.net/jan
I'm having trouble getting classes inside my webservice
class
obj