Re: Web service, generics and complex data types
- From: "John Saunders [MVP]" <john.saunders at trizetto.com>
- Date: Thu, 30 Aug 2007 10:18:55 -0400
"Mike" <mike@xxxxxxxxxxx> wrote in message news:319203BAFD7A4B78B5378D3CB3A385B2@xxxxxxxxx
HI,
I'm having some problems with web services, as I cannot make them do
what I need.
I have a class called Order that has more classes inside.
For example, I have Order. Addresses, in this case Addresses is a
generic collection as (of Address)
What I want is that my web service returns an object Order as it is,
with all its properties as it is mean to be.
Right now, the proxy generated when I reference the service
(Reference.vb) downgrades the object Addresses to an object Address.
What I need is the ability to get (thru the web service) an Order object
as it was created, not downgraded, and also I need the ability to pass
to the web service an object Order so I can persist this object to the
DB thru the web service.
The Web Services platform is meant to be platform-neutral. Generics, in particular generic collections, are a platform-specific feature. As such, they should not be used in web services. In fact, there is no way in WSDL and XSD to describe a generic collection.
But I suspect that you don't actually need a generic collection. You need to pass a set of Address data. Note that I don't say that you need to pass a set of Address objects, because that is fundamentally impossible. But you can pass a set of the data that an Address object is composed of. It seems quite old-fashioned, but you should be passing arrays of Address.
There is a lot of behind-the-scenes magic that makes it easy to use Web Services. That is, they are easy to use, until they aren't easy to use any more.
This magic obscures the process, so I'll briefly describe the process.
1) A client-side development tool (maybe VS "Add Web Reference") requests the WSDL from the server
2) ASP.NET on the server uses the .asmx file to create an instance of the web service class. It uses Reflection to examine the Web Service class and the other types used by that class as parameters and return values. It then creates a WSDL and schema that describes what it found, and returns that to the client-side development tool
3) The client-side tool will probably use the WSDL and schema to create proxy classes. These will be classes that can be serialized into XML that validates against the schema in the WSDL file, and classes that can make calls to the service described by the WSDL
4) You use the proxy classes to produce your client program
5) At run-time, your client program uses the proxy classes to create proxy objects that get serialized to XML that gets sent to the server, sends it to the server, gets XML responses from the server and deserializes the responses back into proxy objects
Note that it is impossible for the client to use your server-side classes, so it will never be using your Order object "as it was created". The client will never be using your Order object at all! If you have a design that depends on the client using your actual Order object, then you should be using .NET Remoting and not Web Services.
--
John Saunders [MVP]
.
- Follow-Ups:
- References:
- Web service, generics and complex data types
- From: Mike
- Web service, generics and complex data types
- Prev by Date: What is a Proxy Class--Newbie Question
- Next by Date: Re: What is a Proxy Class--Newbie Question
- Previous by thread: Web service, generics and complex data types
- Next by thread: Re: Web service, generics and complex data types
- Index(es):
Relevant Pages
|
Loading