WCF and WSDL

By definition the Web Service Description Language (WSDL) is the XML based document that describes a Web Service. It specifies the location of the service and the operation or methods the service exposes. One of the nice features of both WCF and ASMX services is that you don’t have to understand the inner workings of WSDL. Both of these technologies at run time will automatically generate the WSDL for your service.  However, for those times when changing the WSDL is necessary. For example, exposing different method names or even changing the various elements of how your WSDL is implemented. By default WCF expose the service artifacts based on the named classes and attributes defined in the source files. These artifacts are exposed through the endpoint of the service and typically consumed as WSDL by a client at design time. On the client side, the WSDL is then used to write code that builds the proper message format through which it communicates with the service So, the names you choose for classes, methods and parameters can have an impact beyond the application. With WCF you can control all exposed names from the service within the WSDL by modifying the <ServiceContract> and <OperationContract> and <ServiceBehavior> attributes.

For example if we start with the following base WCF service.

When the service is run it generates the following WSDL

If for example you want to change WSDL Port Type you can use the “name” attribute

When the service is run it changes the generated WSDL Port Type as follows

 

For example we wanted to change exposed operation name in the WSDL we can insert the following attribute

When run this changes the WSDL operation name as follows