Tuesday, March 29, 2005

Web services are not distributed objects

One of the most important concepts to understand about the web services framework (WSF) is that it is not a distributed object system. Web services communicate by exchanging messages -- it's more like JMS than RMI. The WSF doesn't support remote references, remote object garbage collection, or any of the other distributed object features developers have come to rely upon in RMI, CORBA, DCOM, or other distributed object systems.

The fundamental purpose of the WSF is to enable interoperability across dissimilar systems that don't necessarily understand concepts such as method overloading, object inheritance, and polymorphism. Hence web service interfaces should not expose these OO concepts.

A service should expose a document-oriented interface rather than an object-oriented interface. The basic best practices are:
  • Flatten object graphs. Don’t expose language-specific object collections, such as maps, lists, or datasets. Instead convert all collections into arrays.
  • Don’t use overloaded methods. Each method should have a different operation name.
  • Expose a "chunky" interface rather than a "chatty" interface. In other words, don’t expose getter and setter operations for every member in the object class.
These best practices relate back to the differentiation between message exchange versus distributed object systems. When using distributed objects, the object resides on the server side, and the client invokes operations on the object using a proxy. The client does not have its own copy of the object. When using a message exchange system, the client side application should have its own object -- not just a proxy. (And – by the way – the client’s object may be different from the server's object.) When the client communicates with the server, it simply passes data, not behavior. It's much more loosely coupled.

It may be necessary to build an abstraction layer between the WSDL interface and the application that implements the service. This abstraction layer performs the necessary mapping between the document-oriented WSDL interface and the application's object model. It also provides much better insulation for flexibility and change.

For best interoperability, developers should use document/literal with the “wrapped” programming convention. .NET uses the “wrapped” style by default. The JAX-RPC specification also requires support for the “wrapped” style. The "wrapped" style supports a programming model that makes document/literal feel like RPC style. "Wrapped" style is very similar to RPC/literal, except for two important distinctions:
  1. .NET supports "wrapped" style, but it doesn't support RPC/literal
  2. "Wrapped" style defines a schema of the full soap body (which makes it very easy to validate), while RPC/Literal only defines type information rather that the full schema of the message elements (which makes validation slightly more complicated).
Please see my previous blog entry on the "wrapped" style for more information.

6 comments:

Anonymous said...

Hi Anne, couldn't agree with you more. Please check out my blog where I posted a link to an article I wrote about the matter for Business Integrayion Journal.

Ignacio Manzano said...

Hi Anne,

I have a two question about wsdl doc/lit wrapped.

1) The output and input messages always must be have the part's name "parameters" ?

for example

<wsdl:message name="Operation_1">
<wsdl:part name="parameters" element="tns:Operation_1Response"/>
</wsdl:message>

<wsdl:message name="Operation_1Response">
<wsdl:part name="parameters" element="tns:Operation_1Response"/>
</wsdl:message>

2) The message's name must be the same that the operation name?

for example:

<wsdl:message name="Operation_1SoapIn" >
<wsdl:part name="parameters" element="tns:Operation_1"/>
</wsdl:message>

<wsdl:message name="Operation_1SoapOut">
<wsdl:part name="parameters" element="tns:Operation_1Response"/>
</wsdl:message>

<wsdl:portType name="WsWrappedWithRefSoap">
<wsdl:operation name="Operation_1">
<wsdl:input message="tns:Operation_1SoapIn"/>
<wsdl:output message="tns:Operation_1SoapOut"/>
</wsdl:operation>
</wsdl:portType>

Thanks!
Ignacio

Ignacio Manzano said...

Sorry, I posted here by mistake.

rahul said...

Hi Annie

Please let me know what are the required changes that need to be done in order to convert a service from RPC\Encoded to Document\Literal. I am using AXIS (Latest Version).

What i did:
In my service that is RPC\Encoded style , i have done changes in its deploy.wsdd.
style="Document",use="literal". and re deployed it.When i accessed its wsdl(axis generates itself) It was according to document\literal. Using this wsdl i generated client code using gsoap. When i made use of that client code it say in its log "SOAP_TAG_MISMATCH" error. i analyed logs and find that may be some namespace issue is thr.

I want to verify my changes and want if u can comment on my issues.

Anonymous said...

My partner and I stumbled over here from a different web page and thought I might check things out. I like what I see so now i am following you. Look forward to going over your web page repeatedly.

movers in marryland 

Unknown said...

Wow, this article is really very good, so that I can't say how happy feeling. The article make every detail of the story depicts streaming with the best, and every movement of the characters all write so lifelike, let me see the waves excited. Groom sherwani