OO WebService

J

Jason B

I'm having trouble getting classes inside my webservice class to be seen and
instantiated like I can with tradiational exe based classes. Am I missing
something or is that an asmx file can only be associated with one class?

I want to be able to write private ProductSupport.Customer obj = new
ProductSupport.Customer();

Thanks,
Jason

public class ProductSupport : System.Web.Services.WebService {

public class Customer {

}

}
 
J

Jan Tielens

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
 
J

Jason B

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
 
J

Jan Tielens

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


Jason B said:
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




Jan Tielens said:
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


seen
and
 
J

Jason B

Jan, very interesting. I hadn't heard of the Factory Design approach. I'll
have to do some more reading there. I cringe at those last minute
requirements meetings. Anyway, I understand the concept of having a class
function return an object to a caller. My original problem is being able to
reference and use that object in the client of a webservice. The only class
I'm able to reference is the native asmx class - no other classes. I tried a
generic "object" and late bound it to the function, but it failed 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


Jan Tielens said:
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


Jason B said:
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




Jan Tielens said:
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 to be seen
and
instantiated like I can with tradiational exe based classes. Am I missing
something or is that an asmx file can only be associated with one class?

I want to be able to write private ProductSupport.Customer obj = new
ProductSupport.Customer();

Thanks,
Jason

public class ProductSupport : System.Web.Services.WebService {

public class Customer {

}

}
 
M

Michel

Hi Jason,

Just to get it clear for me, you have a webmethod:
BaseClass MyWebMethod()

In it you return a subclass of BaseClass.

The client doesn't understand the result.

My guess is your client does not have a reference to the subclass.
All the client gets is an xml string which it has to deserialize into an
object. This is only possible if the client knows about the class in
question. To be sure, try to add another webmethod that returns the
particular class.
I haven't tried this particular situation with soap, but I do use similar
constructs for parameters (i.e. a base class parameter that receives
subclass objects created at the client).

Hope this helps,
Michel

Jason B said:
Jan, very interesting. I hadn't heard of the Factory Design approach. I'll
have to do some more reading there. I cringe at those last minute
requirements meetings. Anyway, I understand the concept of having a class
function return an object to a caller. My original problem is being able to
reference and use that object in the client of a webservice. The only class
I'm able to reference is the native asmx class - no other classes. I tried a
generic "object" and late bound it to the function, but it failed 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


Jan Tielens said:
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


Jason B said:
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 to
be
seen
and
instantiated like I can with tradiational exe based classes. Am I
missing
something or is that an asmx file can only be associated with one class?

I want to be able to write private ProductSupport.Customer obj = new
ProductSupport.Customer();

Thanks,
Jason

public class ProductSupport : System.Web.Services.WebService {

public class Customer {

}

}
 
J

Jason B

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

Michel said:
Hi Jason,

Just to get it clear for me, you have a webmethod:
BaseClass MyWebMethod()

In it you return a subclass of BaseClass.

The client doesn't understand the result.

My guess is your client does not have a reference to the subclass.
All the client gets is an xml string which it has to deserialize into an
object. This is only possible if the client knows about the class in
question. To be sure, try to add another webmethod that returns the
particular class.
I haven't tried this particular situation with soap, but I do use similar
constructs for parameters (i.e. a base class parameter that receives
subclass objects created at the client).

Hope this helps,
Michel

Jason B said:
Jan, very interesting. I hadn't heard of the Factory Design approach. I'll
have to do some more reading there. I cringe at those last minute
requirements meetings. Anyway, I understand the concept of having a class
function return an object to a caller. My original problem is being able to
reference and use that object in the client of a webservice. The only class
I'm able to reference is the native asmx class - no other classes. I
tried
a
generic "object" and late bound it to the function, but it failed 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


Jan Tielens said:
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 work
in
 
J

Jason B

I just got word from a friend that you cannot return objects from or
reference objects in a web service other than the base class orginiated in
the asmx file. This is more the job of remoting.

Does anyone disagree? Maybe this is obviously to everyone else and I'm a
newbie at this.
Jason


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

Michel said:
Hi Jason,

Just to get it clear for me, you have a webmethod:
BaseClass MyWebMethod()

In it you return a subclass of BaseClass.

The client doesn't understand the result.

My guess is your client does not have a reference to the subclass.
All the client gets is an xml string which it has to deserialize into an
object. This is only possible if the client knows about the class in
question. To be sure, try to add another webmethod that returns the
particular class.
I haven't tried this particular situation with soap, but I do use similar
constructs for parameters (i.e. a base class parameter that receives
subclass objects created at the client).

Hope this helps,
Michel

able
to tried
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
to
be
seen
and
instantiated like I can with tradiational exe based classes.
Am
 
D

Dino Chiesa [Microsoft]

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

Michel said:
Hi Jason,

Just to get it clear for me, you have a webmethod:
BaseClass MyWebMethod()

In it you return a subclass of BaseClass.

The client doesn't understand the result.

My guess is your client does not have a reference to the subclass.
All the client gets is an xml string which it has to deserialize into an
object. This is only possible if the client knows about the class in
question. To be sure, try to add another webmethod that returns the
particular class.
I haven't tried this particular situation with soap, but I do use similar
constructs for parameters (i.e. a base class parameter that receives
subclass objects created at the client).

Hope this helps,
Michel

able
to tried
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
to
be
seen
and
instantiated like I can with tradiational exe based classes.
Am
 
J

Jason B

Yes I'm using C#.
I can access webmethods just fine. I can't access webmethods of other
classes other than the default asmx class. Doesn't this make sense the way
I'm explaining it? I'm getting the feeling I'm crazy.

Try this to put yourself in my shoes maybe. Create a webservice (asmx) and
an exe project and reference the web service. Create another class inside
that asmx file with a method. Update the exe project to get the new wsdl
file with your new class members in it.
1. Try to reference the newly created class in the client. You won't be able
to instantiate it. It doesn't exist to the client.
2. Try to see the new method you created in the new class when you run the
asmx file with VS. You won't see the new methods.

A friend told me (over the phone) this can't be done. You have a 1 to 1
relationship between the asmx file and the number of classes it exposes to
the client.
I don't know if I can explain it any differently. Tell me what you think.
Jason


Dino Chiesa said:
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
to Am with
one
obj
 

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,780
Messages
2,569,611
Members
45,276
Latest member
Sawatmakal

Latest Threads

Top