.NET 4.5 Contract First Development: How To Create Service Contracts From Wsdl

The newest iteration of the .NET framework (.NET 4.5) brings along with it a host of new features.  In the service world, one great feature that I have been requesting for quite some time now is the ability to create a service interface along with all of the corresponding data contracts by using a WSDL file.  I am pleased to find that .NET 4.5 provides this feature in the svcutil.exe application through the use of a /serviceContract or /sc flag.  The topic is briefly discussed in the MSDN article titled, “What’s New in Windows Communication Foundation 4.5”.  As you may already know, previous versions of the svcutil executable could be used to generate contracts from WSDL files.  However, the newest version really simplifies the process through the use of the /sc flag.

This feature can be very useful when WSDL file is produced through design phase either by a solution architect or through mutual parties that agree on a contract prior to development and build phases.  When this is the case, either the contract can be created for a future service implementation or contracts can be created so that developers can begin coding for the client side of an interface prior to the endpoint being available.

Pre-Requisites


One thing you will need to follow through this demo is a WSDL file.  WSDL files can be created using a number of tools, such as Sparx Enterprise Architect, Altova XML Spy, or Eclipse.  I took the liberty of creating a WSDL file for this demo.

Equipment.wsdl:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<wsdl:definitions name="Equipment"
	targetNamespace="http://service.bloggedbychris.com/contractfirstdemo/equipment/v1"
	xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
	xmlns:tns="http://service.bloggedbychris.com/contractfirstdemo/equipment/v1"
	xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
	xmlns:xsd1="http://message.bloggedbychris.com/contractfirstdemo/equipment/v1">
	<wsdl:import
		namespace="http://message.bloggedbychris.com/contractfirstdemo/equipment/v1"
		location="EquipmentServiceData.xsd"></wsdl:import>
	<wsdl:types>
		<xsd:schema
			targetNamespace="http://service.bloggedbychris.com/contractfirstdemo/equipment/v1"
			xmlns:xsd="http://www.w3.org/2001/XMLSchema">
			<xsd:import schemaLocation="EquipmentServiceData.xsd"
				namespace="http://message.bloggedbychris.com/contractfirstdemo/equipment/v1"></xsd:import>
			<xsd:element name="EquipmentDetailRequest" type="xsd1:EquipmentDetailRequest"></xsd:element>

			<xsd:element name="EquipmentDetailResponse" type="xsd1:EquipmentDetailResponse"></xsd:element>
			<xsd:element name="EquipmentAvailabilityRequest" type="xsd1:EquipmentAvailabilityRequest">
			</xsd:element>
			<xsd:element name="EquipmentAvailabilityResponse" type="xsd1:EquipmentAvailabilityResponse">
			</xsd:element>

			<xsd:element name="EquipmentOrderRequest" type="xsd1:EquipmentOrderRequest">
			</xsd:element>
			<xsd:element name="EquipmentOrderResponse" type="xsd1:EquipmentOrderResponse">
			</xsd:element>
		</xsd:schema>
	</wsdl:types>

	<wsdl:message name="EquipmentDetailRequest">
		<wsdl:part name="parameters" element="tns:EquipmentDetailRequest">
		</wsdl:part>
	</wsdl:message>
	<wsdl:message name="EquipmentDetailResponse">
		<wsdl:part name="parameters" element="tns:EquipmentDetailResponse">
		</wsdl:part>
	</wsdl:message>
	<wsdl:message name="EquipmentAvailabilityRequest">
		<wsdl:part name="parameters" element="tns:EquipmentAvailabilityRequest">
		</wsdl:part>
	</wsdl:message>
	<wsdl:message name="EquipmentAvailabilityResponse">
		<wsdl:part name="parameters" element="tns:EquipmentAvailabilityResponse">
		</wsdl:part>
	</wsdl:message>
	<wsdl:message name="OrderEquipmentRequest">
		<wsdl:part name="parameters" element="tns:EquipmentOrderRequest">
		</wsdl:part>
	</wsdl:message>
	<wsdl:message name="OrderEquipmentResponse">
		<wsdl:part name="parameters" element="tns:EquipmentOrderResponse">
		</wsdl:part>
	</wsdl:message>
	<wsdl:portType name="EquipmentService">
		<wsdl:operation name="GetEquipmentDetail">
			<wsdl:input message="tns:EquipmentDetailRequest"></wsdl:input>
			<wsdl:output message="tns:EquipmentDetailResponse"></wsdl:output>
		</wsdl:operation>
		<wsdl:operation name="GetEquipmentAvailability">
			<wsdl:input message="tns:EquipmentAvailabilityRequest"></wsdl:input>
			<wsdl:output message="tns:EquipmentAvailabilityResponse"></wsdl:output>
		</wsdl:operation>
		<wsdl:operation name="OrderEquipment">
			<wsdl:input message="tns:OrderEquipmentRequest"></wsdl:input>
			<wsdl:output message="tns:OrderEquipmentResponse"></wsdl:output>
		</wsdl:operation>
	</wsdl:portType>
	<wsdl:binding name="EquipmentSOAP" type="tns:EquipmentService">
		<soap:binding style="document"
			transport="http://schemas.xmlsoap.org/soap/http" />
		<wsdl:operation name="GetEquipmentDetail">
			<soap:operation
				soapAction="http://service.bloggedbychris.com/contractfirstdemo/equipment/v1/GetEquipmentDetail" />
			<wsdl:input>
				<soap:body use="literal" />
			</wsdl:input>
			<wsdl:output>
				<soap:body use="literal" />
			</wsdl:output>
		</wsdl:operation>
		<wsdl:operation name="GetEquipmentAvailability">
			<soap:operation
				soapAction="http://service.bloggedbychris.com/contractfirstdemo/equipment/v1/GetEquipmentAvailability" />
			<wsdl:input>
				<soap:body use="literal" />
			</wsdl:input>
			<wsdl:output>
				<soap:body use="literal" />
			</wsdl:output>
		</wsdl:operation>
		<wsdl:operation name="OrderEquipment">
			<soap:operation
				soapAction="http://service.bloggedbychris.com/contractfirstdemo/equipment/v1/OrderEquipment" />
			<wsdl:input>
				<soap:body use="literal" />
			</wsdl:input>
			<wsdl:output>
				<soap:body use="literal" />
			</wsdl:output>
		</wsdl:operation>
	</wsdl:binding>
	<wsdl:service name="EquipmentService">
		<wsdl:port binding="tns:EquipmentSOAP" name="EquipmentSOAP">
			<soap:address
				location="http://service.bloggedbychris.com/contractfirstdemo/equipment/v1/service" />
		</wsdl:port>
	</wsdl:service>
</wsdl:definitions>

  

The above WSDL references an XSD file, so you will need this as well.

EquipmentServiceData.xsd:

<?xml version="1.0" encoding="UTF-8"?>
<schema targetNamespace="http://message.bloggedbychris.com/contractfirstdemo/equipment/v1" elementFormDefault="qualified" xmlns="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://message.bloggedbychris.com/contractfirstdemo/equipment/v1">

    <complexType name="Equipment">
    	<sequence>
    		<element name="Id" type="string"></element>
    		<element name="Name" type="string"></element>
    		<element name="Description" type="string"></element>
    	</sequence>
    </complexType>

    <complexType name="ShippingInformation">
    	<sequence>
    		<element name="FirstName" type="string" minOccurs="1"
    			maxOccurs="1">
    		</element>
    		<element name="LastName" type="string" minOccurs="1"
    			maxOccurs="1">
    		</element>
    		<element name="StreetLine1" type="string" minOccurs="1"
    			maxOccurs="1">
    		</element>
    		<element name="StreetLine2" type="string" minOccurs="0"
    			maxOccurs="1">
    		</element>
    		<element name="ZipCode" minOccurs="1" maxOccurs="1"
    			type="tns:ZipCodeType">
    		</element>
    		<element name="State" minOccurs="1" maxOccurs="1"
    			type="tns:StateType">
    		</element>
    		<element name="Country" type="string" minOccurs="1" maxOccurs="1"></element>
    	</sequence>
    </complexType>

    <simpleType name="ZipCodeType">
		<restriction base="string">
			<pattern value="0-9{5}(-0-9+)?"></pattern>
		</restriction>
    </simpleType>

    <simpleType name="StateType">
		<restriction base="string">
			<pattern value="A-Z{2}"></pattern>
		</restriction>
    </simpleType>

    <complexType name="EquipmentAvailabilityRequest">
    	<sequence>
    		<element name="EquipmentId" type="int" minOccurs="1" maxOccurs="1"></element>
    	</sequence>
    </complexType>

    <complexType name="EquipmentAvailabilityResponse">
    	<sequence>
    		<element name="QuantityAvailable" type="int" minOccurs="1" maxOccurs="1"></element>
    	</sequence>
    </complexType>

    <complexType name="EquipmentOrder">
    	<sequence>
    		<element name="Id" type="int" minOccurs="1"
    			maxOccurs="1">
    		</element>
    		<element name="EquipmentId" type="int" minOccurs="1"
    			maxOccurs="1">
    		</element>
    		<element name="CreateDate" type="dateTime" minOccurs="1"
    			maxOccurs="1">
    		</element>
    		<element name="Quantity" type="int" minOccurs="1"
    			maxOccurs="1">
    		</element>
            <element name="FulfilledDate" type="dateTime" minOccurs="1" maxOccurs="1"></element>
        </sequence>
    </complexType>

    <complexType name="EquipmentOrderRequest">
    	<sequence>
    		<element name="EquipmentId" type="int" minOccurs="1"
    			maxOccurs="1">
    		</element>
    		<element name="Quantity" type="int" minOccurs="1" maxOccurs="1"></element>
    	</sequence>
    </complexType>

    <complexType name="EquipmentOrderResponse">
    	<sequence>
    		<element name="Order" type="tns:EquipmentOrder" minOccurs="1" maxOccurs="1"></element>
    	</sequence>
    </complexType>

    <complexType name="EquipmentDetailRequest">
    	<sequence minOccurs="1" maxOccurs="1">

    		<element name="Search" type="tns:Search"></element>
    	</sequence>
    </complexType>

    <complexType name="EquipmentDetailResponse">
    	<sequence>
    		<element name="Equipment" type="tns:Equipment" minOccurs="0" maxOccurs="unbounded"></element>
    	</sequence>
    </complexType>

    <complexType name="EquipmentSearch">
    	<sequence>
    		<element name="SearchValue" type="string" minOccurs="1" maxOccurs="1"></element>
    	</sequence>
    </complexType>

    <complexType name="EquipmentIdSearch">
    	<complexContent>
    		<extension base="tns:EquipmentSearch"></extension>
    	</complexContent>
    </complexType>

    <complexType name="EquipmentNameSearch">
    	<complexContent>
    		<extension base="tns:EquipmentSearch">
    		</extension>
    	</complexContent>
    </complexType>

    <complexType name="Search">
		<choice>
 			<element name="EquipmentId"
 				type="tns:EquipmentIdSearch">
 			</element>
 			<element name="EquipmentName"
 				type="tns:EquipmentNameSearch">
 			</element>
 		</choice>
    </complexType>
</schema>

 

Beyond the two files above, you will need to have the .NET 4.5 framework installed.  At the time I write this post, only the RC is available.

Generating the Contract


Once you have the WSDL file ready and .NET 4.5 installed, we are ready to proceed with generating the service contracts using the service utility.  In this section, my examples assume that you are using the Equipment.wsdl file from above and the corresponding EquipmentServiceData.xsd file.

With those two files in hand, fire up a PowerShell window or command line.  Change directory into the directory where the WSDL and XSD file reside:

PS C:\> cd 'C:\Users\youruser\Desktop\Contract First Demo'

 

Now, use the the service utility to create the necessary data and service contracts.  This is done through the use of either the /serviceContract flag or the /sc short form.  You can provide an optional /out: parameter, but I do not in the example, which results in an Equipment.cs file being generated in the current directory.  Lastly, make sure you provide both the WSDL and XSD file as the last inputs to the utility.

PS C:\Users\myersch\Desktop\Contract First Demo> & "C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools\SvcUtil.exe" /sc .\Equipment.wsdl .\EquipmentServiceData.xsd
Microsoft (R) Service Model Metadata Tool
[Microsoft (R) Windows (R) Communication Foundation, Version 4.0.30319.17626]
Copyright (c) Microsoft Corporation.  All rights reserved.

Generating files...

 

If everything was done successfully, you should end up with a file that reflects the following.

Equipment.cs:

//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:4.0.30319.17626
//
//     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(Namespace="http://service.bloggedbychris.com/contractfirstdemo/equipment/v1", ConfigurationName="EquipmentService")]
public interface EquipmentService
{

    // CODEGEN: Generating message contract since the wrapper name (EquipmentDetailRequest) of message GetEquipmentDetailRequest does not match the default value (GetEquipmentDetail)
    [System.ServiceModel.OperationContractAttribute(Action="http://service.bloggedbychris.com/contractfirstdemo/equipment/v1/GetEquipmentDeta" +
        "il")]
    [System.ServiceModel.XmlSerializerFormatAttribute()]
    [System.ServiceModel.ServiceKnownTypeAttribute(typeof(EquipmentSearch))]
    GetEquipmentDetailResponse GetEquipmentDetail(GetEquipmentDetailRequest request);

    // CODEGEN: Generating message contract since the wrapper name (EquipmentAvailabilityRequest) of message GetEquipmentAvailabilityRequest does not match the default value (GetEquipmentAvailability)
    [System.ServiceModel.OperationContractAttribute(Action="http://service.bloggedbychris.com/contractfirstdemo/equipment/v1/GetEquipmentAvai" +
        "lability")]
    [System.ServiceModel.XmlSerializerFormatAttribute()]
    [System.ServiceModel.ServiceKnownTypeAttribute(typeof(EquipmentSearch))]
    GetEquipmentAvailabilityResponse GetEquipmentAvailability(GetEquipmentAvailabilityRequest request);

    // CODEGEN: Generating message contract since the wrapper name (EquipmentOrderRequest) of message OrderEquipmentRequest does not match the default value (OrderEquipment)
    [System.ServiceModel.OperationContractAttribute(Action="http://service.bloggedbychris.com/contractfirstdemo/equipment/v1/OrderEquipment")]
    [System.ServiceModel.XmlSerializerFormatAttribute()]
    [System.ServiceModel.ServiceKnownTypeAttribute(typeof(EquipmentSearch))]
    OrderEquipmentResponse OrderEquipment(OrderEquipmentRequest request);
}

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "4.0.30319.17626")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://message.bloggedbychris.com/contractfirstdemo/equipment/v1")]
public partial class Search
{

    private EquipmentSearch itemField;

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute("EquipmentId", typeof(EquipmentIdSearch), Order=0)]
    [System.Xml.Serialization.XmlElementAttribute("EquipmentName", typeof(EquipmentNameSearch), Order=0)]
    public EquipmentSearch Item
    {
        get
        {
            return this.itemField;
        }
        set
        {
            this.itemField = value;
        }
    }
}

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "4.0.30319.17626")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://message.bloggedbychris.com/contractfirstdemo/equipment/v1")]
public partial class EquipmentIdSearch : EquipmentSearch
{
}

/// <remarks/>
[System.Xml.Serialization.XmlIncludeAttribute(typeof(EquipmentNameSearch))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(EquipmentIdSearch))]
[System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "4.0.30319.17626")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://message.bloggedbychris.com/contractfirstdemo/equipment/v1")]
public partial class EquipmentSearch
{

    private string searchValueField;

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Order=0)]
    public string SearchValue
    {
        get
        {
            return this.searchValueField;
        }
        set
        {
            this.searchValueField = value;
        }
    }
}

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "4.0.30319.17626")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://message.bloggedbychris.com/contractfirstdemo/equipment/v1")]
public partial class EquipmentOrder
{

    private int idField;

    private int equipmentIdField;

    private System.DateTime createDateField;

    private int quantityField;

    private System.DateTime fulfilledDateField;

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Order=0)]
    public int Id
    {
        get
        {
            return this.idField;
        }
        set
        {
            this.idField = value;
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Order=1)]
    public int EquipmentId
    {
        get
        {
            return this.equipmentIdField;
        }
        set
        {
            this.equipmentIdField = value;
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Order=2)]
    public System.DateTime CreateDate
    {
        get
        {
            return this.createDateField;
        }
        set
        {
            this.createDateField = value;
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Order=3)]
    public int Quantity
    {
        get
        {
            return this.quantityField;
        }
        set
        {
            this.quantityField = value;
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Order=4)]
    public System.DateTime FulfilledDate
    {
        get
        {
            return this.fulfilledDateField;
        }
        set
        {
            this.fulfilledDateField = value;
        }
    }
}

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "4.0.30319.17626")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://message.bloggedbychris.com/contractfirstdemo/equipment/v1")]
public partial class Equipment
{

    private string idField;

    private string nameField;

    private string descriptionField;

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Order=0)]
    public string Id
    {
        get
        {
            return this.idField;
        }
        set
        {
            this.idField = value;
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Order=1)]
    public string Name
    {
        get
        {
            return this.nameField;
        }
        set
        {
            this.nameField = value;
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Order=2)]
    public string Description
    {
        get
        {
            return this.descriptionField;
        }
        set
        {
            this.descriptionField = value;
        }
    }
}

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "4.0.30319.17626")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://message.bloggedbychris.com/contractfirstdemo/equipment/v1")]
public partial class EquipmentNameSearch : EquipmentSearch
{
}

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
[System.ServiceModel.MessageContractAttribute(WrapperName="EquipmentDetailRequest", WrapperNamespace="http://service.bloggedbychris.com/contractfirstdemo/equipment/v1", IsWrapped=true)]
public partial class GetEquipmentDetailRequest
{

    [System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://message.bloggedbychris.com/contractfirstdemo/equipment/v1", Order=0)]
    [System.Xml.Serialization.XmlElementAttribute(Namespace="http://message.bloggedbychris.com/contractfirstdemo/equipment/v1")]
    public Search Search;

    public GetEquipmentDetailRequest()
    {
    }

    public GetEquipmentDetailRequest(Search Search)
    {
        this.Search = Search;
    }
}

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
[System.ServiceModel.MessageContractAttribute(WrapperName="EquipmentDetailResponse", WrapperNamespace="http://service.bloggedbychris.com/contractfirstdemo/equipment/v1", IsWrapped=true)]
public partial class GetEquipmentDetailResponse
{

    [System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://message.bloggedbychris.com/contractfirstdemo/equipment/v1", Order=0)]
    [System.Xml.Serialization.XmlElementAttribute("Equipment", Namespace="http://message.bloggedbychris.com/contractfirstdemo/equipment/v1")]
    public Equipment[] Equipment;

    public GetEquipmentDetailResponse()
    {
    }

    public GetEquipmentDetailResponse(Equipment[] Equipment)
    {
        this.Equipment = Equipment;
    }
}

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
[System.ServiceModel.MessageContractAttribute(WrapperName="EquipmentAvailabilityRequest", WrapperNamespace="http://service.bloggedbychris.com/contractfirstdemo/equipment/v1", IsWrapped=true)]
public partial class GetEquipmentAvailabilityRequest
{

    [System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://message.bloggedbychris.com/contractfirstdemo/equipment/v1", Order=0)]
    [System.Xml.Serialization.XmlElementAttribute(Namespace="http://message.bloggedbychris.com/contractfirstdemo/equipment/v1")]
    public int EquipmentId;

    public GetEquipmentAvailabilityRequest()
    {
    }

    public GetEquipmentAvailabilityRequest(int EquipmentId)
    {
        this.EquipmentId = EquipmentId;
    }
}

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
[System.ServiceModel.MessageContractAttribute(WrapperName="EquipmentAvailabilityResponse", WrapperNamespace="http://service.bloggedbychris.com/contractfirstdemo/equipment/v1", IsWrapped=true)]
public partial class GetEquipmentAvailabilityResponse
{

    [System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://message.bloggedbychris.com/contractfirstdemo/equipment/v1", Order=0)]
    [System.Xml.Serialization.XmlElementAttribute(Namespace="http://message.bloggedbychris.com/contractfirstdemo/equipment/v1")]
    public int QuantityAvailable;

    public GetEquipmentAvailabilityResponse()
    {
    }

    public GetEquipmentAvailabilityResponse(int QuantityAvailable)
    {
        this.QuantityAvailable = QuantityAvailable;
    }
}

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
[System.ServiceModel.MessageContractAttribute(WrapperName="EquipmentOrderRequest", WrapperNamespace="http://service.bloggedbychris.com/contractfirstdemo/equipment/v1", IsWrapped=true)]
public partial class OrderEquipmentRequest
{

    [System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://message.bloggedbychris.com/contractfirstdemo/equipment/v1", Order=0)]
    [System.Xml.Serialization.XmlElementAttribute(Namespace="http://message.bloggedbychris.com/contractfirstdemo/equipment/v1")]
    public int EquipmentId;

    [System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://message.bloggedbychris.com/contractfirstdemo/equipment/v1", Order=1)]
    [System.Xml.Serialization.XmlElementAttribute(Namespace="http://message.bloggedbychris.com/contractfirstdemo/equipment/v1")]
    public int Quantity;

    public OrderEquipmentRequest()
    {
    }

    public OrderEquipmentRequest(int EquipmentId, int Quantity)
    {
        this.EquipmentId = EquipmentId;
        this.Quantity = Quantity;
    }
}

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
[System.ServiceModel.MessageContractAttribute(WrapperName="EquipmentOrderResponse", WrapperNamespace="http://service.bloggedbychris.com/contractfirstdemo/equipment/v1", IsWrapped=true)]
public partial class OrderEquipmentResponse
{

    [System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://message.bloggedbychris.com/contractfirstdemo/equipment/v1", Order=0)]
    [System.Xml.Serialization.XmlElementAttribute(Namespace="http://message.bloggedbychris.com/contractfirstdemo/equipment/v1")]
    public EquipmentOrder Order;

    public OrderEquipmentResponse()
    {
    }

    public OrderEquipmentResponse(EquipmentOrder Order)
    {
        this.Order = Order;
    }
}

 

I won’t go into the details of the code that is generated.  It is mainly important to realize that the service interface is generated and all necessary data contract elements are generated as well.  This provides you with the necessary skeleton to either write your service client or in order to clean up the code and implement a service implementation that exposes the generated interface.  You may also want to note that DataContract serialization is not used and instead MessageContract and XML serialization attributes are used.  This may not be desirable, in which case you will want to experiment with the other command line options that can be used along with the service utility,  such as /serializer:DataContractSerializer.

 

Conclusion


Although, this is a very short tutorial and not extremely in depth, I hope that it gives you an idea how useful the described use of the service utility can be.  It can be very useful when contracts are created prior to code as a result of Interface Control Documents or other contract first design mechanisms.

If you had any trouble following along with this tutorial, please leave me a comment and let me know which sections I can improve.  Comments of gratitude are always welcome as well.  I look forward to hearing from you in the comments section.  If you like this post please tweet it or share it with your friends on Facebook.

Tags: , , ,

Reader's Comments »

  1. By Lionel on May 21, 2015 at 8:33 am

    Hello,
    Excuse me, I do not speak good English.
    I have a project with a wsdl and several XSD imported into the wsdl.
    When I generated the class wcf there is no reference to xsd file.
    In fact, I do not understand the utility XSD in the original wsdl and by which they are replaced in the wcf class.
    Thank you for your help.
    Lionel

  2. By Evelyn on March 2, 2016 at 9:22 am

    hello,i am facing the some poerlbm when i run the Axis/c Wsdl2c tool.when i run the commandWSDL2C.bat Calculator.wsdl -d adb -ui get the errorException in thread main java.lang.NoClassDefFoundError: Calculator/wsdlCaused by: java.lang.ClassNotFoundException: Calculator.wsdlat java.net.URLClassLoader$1.run(Unknown Source)at java.security.AccessController.doPrivileged(Native Method)at java.net.URLClassLoader.findClass(Unknown Source)at java.lang.ClassLoader.loadClass(Unknown Source)at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)at java.lang.ClassLoader.loadClass(Unknown Source)Could not find the main class: Calculator.wsdl. Program will exit.I think that it’s need of seeting the CLASSPATH to the JDK.it is really necessary to set the CLASSPATH..???I already set the AXIS_HOME as Environment variablePLS RPLYAMIT TARE

Leave a Reply