This post originated from an RSS feed registered with .NET Buzz
by Christian Weyer.
Original Post: The Web services empire strikes back - Proxy Type Sharing
Feed Title: Christian Weyer: Web Services & .NET
Feed URL: http://www.asp.net/err404.htm?aspxerrorpath=/cweyer/Rss.aspx
Feed Description: Philosophizing about and criticizing the brave new world ...
This one seems just like a small improvement, but I am sure a lot of developers will clap hands now. When having a Web service that exposes a method for querying, let's say, the status of a certain order, then it eventually will describe this order status information with a custom schema called OrderStatusInfo. At a later stage there might be a new Web service for placing orders from potentially any client application. This Web service will take an order and return information about the order status. As we already have an OrderStatusInfo schema we want to use this one, not a newly generated one.
When we now use wsdl.exe or the 'Add Web Reference...' dialog to add both services to any consumer application in order to create a proxy implementation for the services, we will get an error. The following command
will produce the following error when the WSDL either contains or references the exact same OrderStatusInfo schema.
Error: Cannot add service description with targetNamespace='http://msdn.microsoft.com/demos/Orders': schema with targetNamespace='http://msdn.microsoft.com/demos/Orders' already present in the description collection.
That's fine, that's correct. But what happens when we build two separate proxies for the two services? Then a new proxy implementation file would be generated for each service as expected, but so would another OrderStatusInfo representation. This prevents the client from utilizing an instance of either one of the CLR representations with both services. In order to enable a feature called proxy type sharing in our generated proxy file, we can use a new switch on the wsdl.exe tool:
This will result in one file called ServiceProxies.cs which contains the proxy implementations for the OrderEntry and OrderStatus information as well as one single .NET representation of the OrderStatusInfo schema. Voila.
And please notice: this feature is not meant to share types between services and classes! We do not want to break one of the tenets of service orientation.