Contract First development comes to us in .NET 4.5 WCF as the ability to create the service interface and data contract from a WSDL file. The WSDL file is generated in the svcutil.exe
application with the /servicecontract
flag.
This provides an excellent way to parallelize development since we can work on the backend service while it is being constructed, given that the service requirements and contract have been defined beforehand.
In this recipe, we will see how to use this new feature.
In order to use this recipe, you should have Visual Studio 2012 installed and a WSDL contract. For this recipe, we will use the dynamically generated web service we implemented in the first recipe.
In this recipe, we are going to generate a client for a WSDL file.
?wsdl
to the address. You should get something like http://localhost:58997/AsyncService.svc?wsdl
. Note that the port might change. It will generate an XML file with the WSDL definition and display it in our browser as follows:Visual Studio tools
folder and open the VS2012 Tools
command prompt corresponding to your CPU.svcutil /sc http://localhost:58997/AsyncService.svc?wsdl
/sc
of the /servicecontract
flag on our command.ASyncService.cs
has been generated, as we can see in the following screenshot:AsyncServices.cs
in our case.//------------------------------------------------------------------------------ // <auto-generated> // This code was generated by a tool. // Runtime Version:4.0.30319.17914 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. // </auto-generated> //------------------------------------------------------------------------------ [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")] [System.ServiceModel.ServiceContractAttribute(ConfigurationName="IAsyncService")] public interface IAsyncService { [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IAsyncService/DoWork", ReplyAction="http://tempuri.org/IAsyncService/DoWorkResponse")] Int DoWork(); }