Sponsored Links


Resources

.NET Research Library
Get .NET related white papers, case studies and webcasts

TSS Featured Entry: The Web Services Empire Strikes Back - Proxy Type SharingTSS Featured Entry: The Web Services Empire Strikes Back - Proxy Type SharingTSS Featured Entry: The Web Services Empire Strikes Back - Proxy Type Sharing Discuss Discuss Discuss Printer friendly Printer friendly Printer friendly Direct to Blog Entry Direct to Blog Entry Direct to Blog Entry

Proxy Type Sharing

Still a few to go ...

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

wsdl.exe /out:Proxies.cs  http://localhost:780/OrderService/OrderEntry.asmx?WSDL
http://localhost:780/OrderService/OrderStatus.asmx?WSDL

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:

wsdl.exe /out:ServiceProxies.cs /shareTypes
http://localhost:780/OrderService/OrderEntry.asmx?WSDL
http://localhost:780/OrderService/OrderStatus.asmx?WSDL

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.



About the author

Christian Weyer
Blog: http://weblogs.asp.net/cweyer/

Christian Weyer is co-founder of thinktecture (http://www.thinktecture.com/), a company aiding software architects and developers in realizing projects with .NET and distributed applications technologies. He is a recognized XML, Web Services and service-orientation expert. As a Microsoft MVP and one of the few independent Microsoft Regional Directors, he has made a name for himself in the developer community. He has spoken at many well-known developer conferences and forums worldwide and is a published author, editor and writer of numerous articles for various German and international technical magazines.

News | Blogs | Discussions | Tech talks | White Papers | Downloads | Articles | Media kit | About
All Content Copyright ©2007 TheServerSide Privacy Policy
Site Map