Christian Weyer: Smells like service spirit

What's first?

The Web services empire strikes back - Contract-first with .NET 'IDL'

Part 1: The Web services empire strikes back - Introductory thoughts
Part 2: The Web services empire strikes back - Inner Workings
Part 3: The Web services empire strikes back - Web Services in Visual Studio 2005
Part 4: The Web services empire strikes back - WS-I BP Conformance
Part 5: The Web services empire strikes back - Custom XML Serialization
Part 6: The Web services empire strikes back - Proxy Type Sharing

Clemens thinks 'IDL' is good and often enough to hammer down your services interface and message contract - well somehow, yes.
But we do not have to wait for Indigo, just some few months for Whidbey. T
hings really get better with ASMX v2 in Whidbey.

The following description assumes that you already have an exisiting WSDL (or a bunch of them) and then generate code from it. But the process can also be turned around: First code your interface in .NET and voila... you have the code-based contract-first approach rather than the schema-based one with XSD and WSDL.

ASMX v2 will generate a different interface for each binding in a WSDL description. E.g.:

[WebServiceBinding(Name="OrderBinding", Namespace="urn:...")]
public interface IOrderEntry
{
      [WebMethod]
      [SoapDocumentMethod(...)]
      string PlaceOrder(Order order);

      [WebMethod]
      [SoapDocumentMethod(...)]
      string UpdateOrder(Order order);

}

Each interface has the WebServiceBindingAttribute with the binding's name and namespace. At runtime, ASMX reflects over the interfaces that a user's class implements to find all WebServiceBinding and WebMethod attributes. A class that implements an interface which has the WebServiceBindingAttribute can't itself have any Web services or XML serialization attributes. Makes sense but is very important!
Obviously, a class can implement multiple interfaces each corresponding to a different WSDL binding, but a given binding cannot be split across multiple interfaces.
If an interface inherits from another interface, at most one of the interfaces can have the WebServiceBindingAttribute. This is analogous to WSDL not allowing portType inheritance.
The generated interface has the same name as the binding name and is prefixed with 'I' to indicate "Interface". Multiple bindings can be passed to the code generation process (e.g. with wsdl.exe) in one or more WSDL files. Each binding will then yield a different interface.

And as already stated at the beginning of this article: Just use this approach reversely and you are all set to design your contract-first Web services in 'IDL'.

Comments

No Comments