Re: ASP .NET 2.0 web service beginner question - Multiple classes
- From: "John Saunders" <no@xxxxxxxxxxxxxxxx>
- Date: Fri, 10 Oct 2008 12:55:43 -0400
<crowl@xxxxxx> wrote in message news:688236b8-42c6-4847-9db7-a7fbb6499994@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I followed a few "Hello World" examples for asp web service and it
works fine. Now I want to provide the clients multiple classes they
can work with, lets say Class1, Class2, Class3.
I have created a new asp.net web service project in VS and it created
Service.asmx with
public class Service : System.Web.Services.WebService ...
Now I have added 3 Classes (Class1, Class2, Class3) by using -> Add
New Item ..., added properties and methods. All compiled well, but if
I tried to use (find) the classes in the client application there is
only the Service object nor other objects to work with. What I have to
do that Class1, Class2 and Class3 is also available at the client?
None of your server-side classes will ever be available on the client. Your "Service" class is not available on the client. Don't believe me? Add a private method to your "Service" class, and then go update the web reference on the client and see if the private method show up there.
In fact, if you go look at the "Service" class that the client uses, you'll see that it is totally different from what you wrote on the server. It happens to have some of the same method names as your server-side class. The signatures of those methods happens to be similar, or maybe even the same. But the methods themselves are totally different.
That's because the client has a Proxy version of "Service", not the real thing. The proxy class is for the purpose of calling your real "Service". It keeps the client from having to manipulate XML and handle the underlying protocol stuff needed to talk to a web service. The client can pretend that it is calling a real method on a real class.
There are no proxy versions of Class1, Class2 or Class3. That is because they are not needed in order to call your service. I bet your service has no web methods that take an instance of any of those three classes as parameters, nor methods that return an instance of one of those classes. Only if they are needed to call the service will a proxy class be created for any of your server-side classes.
Note that these extra proxy classes will not have any methods, events, indexers or operations. They will only have properties. That is because this is the only thing necessary to communicate with your web service. In fact, the proxy classes will not have the "real" properties - they only have properties that permit the data to be serialized into XML so that it can be sent to your service, or deserialized from XML so that the data can be received from your service.
If you simply have some code that you want a client of your web service to be able to call, in order to perform some function that does not directly involve your service, then you need to put that into a class library and ship the library so that the clients have it. Of course, this won't help with clients that are not written in .NET.
--
John Saunders | MVP - Connected System Developer
.
- References:
- Prev by Date: ASP .NET 2.0 web service beginner question - Multiple classes
- Next by Date: IIS question
- Previous by thread: ASP .NET 2.0 web service beginner question - Multiple classes
- Next by thread: IIS question
- Index(es):
Relevant Pages
|
Loading