SoapUI and WCF Service testing

The web.config that is create when you create a new WCF service application does not work with SoapUI. Retrieving the WSDL will work fine but when you execute a operation on the service the following message will appear:

<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing">
   <s:Header>
      <a:Action s:mustUnderstand="1">http://www.w3.org/2005/08/addressing/soap/fault</a:Action>
   </s:Header>
   <s:Body>
      <s:Fault>
         <s:Code>
            <s:Value>s:Sender</s:Value>
            <s:Subcode>
               <s:Value xmlns:a="http://schemas.xmlsoap.org/ws/2005/02/sc">a:BadContextToken</s:Value>
            </s:Subcode>
         </s:Code>
         <s:Reason>
            <s:Text xml:lang="en-US">The message could not be processed. This is most likely because the action 'http://tempuri.org/IService1/EnrollRight' is incorrect or because the message contains an invalid or expired security context token or because there is a mismatch between bindings. The security context token would be invalid if the service aborted the channel due to inactivity. To prevent the service from aborting idle sessions prematurely increase the Receive timeout on the service endpoint's binding.</s:Text>
         </s:Reason>
      </s:Fault>
   </s:Body>
</s:Envelope>

A solution to this problem (at least for testing purposes) is to add a custom wsHttpBinding. Create a new WCF Service application C# project. Delete all text from the web.config and add replace it with the markup below.

<?xml version="1.0"?>
<configuration>
  <system.serviceModel>

    <behaviors>
      <serviceBehaviors>
        <behavior name="Service1Behavior">
          <serviceMetadata httpGetEnabled="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>

    <bindings>
      <wsHttpBinding>
        <binding name="wsHttpBindingNoSecurity">
          <security mode="None"/>
        </binding>
      </wsHttpBinding>
    </bindings>

    <services>
      <service name="WcfService1.Service1" behaviorConfiguration="Service1Behavior">
        <endpoint address="" binding="wsHttpBinding" bindingConfiguration="wsHttpBindingNoSecurity" contract="WcfService1.IService1"/>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>

  </system.serviceModel>

  <system.web>
    <compilation debug="true"/>
  </system.web>

</configuration>

Important to note is that we have a custom wsHttpBinding with the security mode set to “None”. This is necessary for SoapUI to work with this service!

Now you have to create a new SoapUI project. Point it to the ?wsdl for this services and the project is created with a default request for all operations. Open the first request and press the WS-A button (on the bottom of the request editor). Check “Enable WS-A addressing”, “Add default wsa:Action” and “Add default wsa:To”.

Now execute the request and you get a proper response!

This entry was posted in C#, SoapUI, WCF and tagged , . Bookmark the permalink.

2 Responses to SoapUI and WCF Service testing

  1. Pingback: SoapUI with WCF Service testing - Websphere Tutorial

  2. Vincs says:

    It worked for me thanks !

Leave a comment