Monday, October 31, 2005
In my previous post, I commented on the 4 tenets (i.e. principles) of a SOA.  One of these tenets is, Services share schemas and contracts, not classes or types.  Most developers understand what this means, however, in Visual Studio (VS), it isnt so easy to make this so because VS assumes an XML-based RPC view of Web Services.  Here is what I mean.
 
The .NET Framework makes it extremely easy to create and deploy a Web Service, which is the primary delivery model for a SOA.  The process in VS is deceptively simple you add an .asmx file to your project, add a couple of methods, then build your solution, and voila, you have a Web Service.  In the background, VS generates a WSDL on the server side and a client proxy on the client side.  VS quietly handles all of this for you, which is not necessarily a good thing as mentioned above, VS assumes an XML-based RPC view of web services.
 
There is concept in Web Services development called contract-first or contract-driven development.  Basically, instead of letting Visual Studio generate a WSDL file for you, you should write this WSDL by hand using a WSDL, XML or text editor.  BizTalk developers get the virtue of contract-first development, we have been doing it for years.
 
Btw, WSDL stands for Web Services Description Language.  It is an XML format used to describe a Web Services interface by defining its operations and message exchange patterns.  The actual messages are defined using a schema definition language like XSD.
 
Why would you want to write your WSDL by hand when VS generates this for you?  Letting VS generate your WSDL for you is like picking up your cell phone from a phone company and then letting the phone company handle the contract for you.  Sure, you get your cell phone, but you dont know what you are committed to from a contract perspective.
 
By writing your own WSDL, you have complete control over how your Web Service will be seen to the outside world, including its interface and data structures.  In other words, you have designed it.  This is really a continuation of the idea of contract-driven development that has been around for years - the idea of first creating a contract that your object will implement and that your clients will consume.
 
However, writing WSDL to your Web Services by hand is not such an easy task and there are not really any great tools out there to help out.  In addition, the format takes a bit getting used to and then after you have created your WSDL, you then need to create the client-side proxy and the server-side Web Service code.
 
There is a great VS add-in called WSContractFirst that was written by Christian Weyer in an effort to make contract-first development easier.  Using this VS add-in, you can generate the code for client-side proxies and server-side Web Services based on the WSDL file right inside of VS.
 
I found this "hack" in James Averys most excellent book called, Visual Studio Hacks Tips and Tools for Turbocharging the IDE.  Thanks James!
Monday, October 31, 2005 3:33:14 AM (Pacific Standard Time, UTC-08:00)  #    Comments [0]
Comments are closed.