What VS provides is implementation-first: Developer writes web methods first, then VS generates WSDL (contract) to allow client developer to implement web service client.
The advantage of implementation-first approach is that it is quite easy to develop a web service. Developer need not write complicated WSDL file manually. When web service client accesses the web service, .NET framework will reflect web methods in web service code and generate WSDL dynamically.
The disadvantages of implementation-first approach are:
- Web service developer can change web method easily, which may change the generated WSDL accidentally or without enough warning. This will break the contract between web service and client.
- Web service developer may ignore the compatibility of generated WSDL to include complex object type, like DataSet. This will make Java client difficult to get result because DataSet is only used in .NET framework, not Java framework.
So, how can we use current tools to develop web service? Actually, we can use implementation-first approach in the beginning:
- We can write web methods in Visual Studio without put logic code inside. Then we can let VS generate the complex WSDL for us.
- We examine the WSDL to make sure it does not include .NET specific data types. We may add more parameters to it.
- If we changed the WSDL, we can re-generate web service code using "wsdl.exe /server <WebService WSDL file>"
- When the contract need modification, we should explicitly update the WSDL file and re-generate web service code. We cannot modify web method code directly. This step may overwrite original code, so it is a good idea to separate implementation code into another file
If we follows the steps above, we should be able to keep interoperability between web service and client.