Click here to Skip to main content
15,894,362 members
Articles / Web Development / ASP.NET

How to Mock a WCF Service

Rate me:
Please Sign up or sign in to vote.
4.64/5 (11 votes)
27 Jan 2012CPOL3 min read 93.2K   2K   25  
How to Mock a WCF Service while writing a unit test
<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" xmlns:wsa10="http://www.w3.org/2005/08/addressing" xmlns:tns="http://tempuri.org/" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="WCFService" targetNamespace="http://tempuri.org/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
  <wsdl:types>
    <xsd:schema targetNamespace="http://tempuri.org/Imports">
      <xsd:import schemaLocation="http://localhost/WCFService/WCFService.svc?xsd=xsd0" namespace="http://tempuri.org/" />
      <xsd:import schemaLocation="http://localhost/WCFService/WCFService.svc?xsd=xsd1" namespace="http://schemas.microsoft.com/2003/10/Serialization/" />
      <xsd:import schemaLocation="http://localhost/WCFService/WCFService.svc?xsd=xsd2" namespace="http://schemas.datacontract.org/2004/07/WCFService" />
    </xsd:schema>
  </wsdl:types>
  <wsdl:message name="IWCFService_GetData_InputMessage">
    <wsdl:part name="parameters" element="tns:GetData" />
  </wsdl:message>
  <wsdl:message name="IWCFService_GetData_OutputMessage">
    <wsdl:part name="parameters" element="tns:GetDataResponse" />
  </wsdl:message>
  <wsdl:message name="IWCFService_GetDataUsingDataContract_InputMessage">
    <wsdl:part name="parameters" element="tns:GetDataUsingDataContract" />
  </wsdl:message>
  <wsdl:message name="IWCFService_GetDataUsingDataContract_OutputMessage">
    <wsdl:part name="parameters" element="tns:GetDataUsingDataContractResponse" />
  </wsdl:message>
  <wsdl:portType name="IWCFService">
    <wsdl:operation name="GetData">
      <wsdl:input wsaw:Action="http://tempuri.org/IWCFService/GetData" message="tns:IWCFService_GetData_InputMessage" />
      <wsdl:output wsaw:Action="http://tempuri.org/IWCFService/GetDataResponse" message="tns:IWCFService_GetData_OutputMessage" />
    </wsdl:operation>
    <wsdl:operation name="GetDataUsingDataContract">
      <wsdl:input wsaw:Action="http://tempuri.org/IWCFService/GetDataUsingDataContract" message="tns:IWCFService_GetDataUsingDataContract_InputMessage" />
      <wsdl:output wsaw:Action="http://tempuri.org/IWCFService/GetDataUsingDataContractResponse" message="tns:IWCFService_GetDataUsingDataContract_OutputMessage" />
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="BasicHttpBinding_IWCFService" type="tns:IWCFService">
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
    <wsdl:operation name="GetData">
      <soap:operation soapAction="http://tempuri.org/IWCFService/GetData" style="document" />
      <wsdl:input>
        <soap:body use="literal" />
      </wsdl:input>
      <wsdl:output>
        <soap:body use="literal" />
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="GetDataUsingDataContract">
      <soap:operation soapAction="http://tempuri.org/IWCFService/GetDataUsingDataContract" style="document" />
      <wsdl:input>
        <soap:body use="literal" />
      </wsdl:input>
      <wsdl:output>
        <soap:body use="literal" />
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="WCFService">
    <wsdl:port name="BasicHttpBinding_IWCFService" binding="tns:BasicHttpBinding_IWCFService">
      <soap:address location="http://localhost/WCFService/WCFService.svc" />
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Program Manager
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions