Monday, February 13, 2012

WCF : soapUI error "BadContextToken"

 

While soapUI is a really useful tool for web service unit testing, it doesn’t work with WCF.

In particular, with the default "wsHttpBinding", you get the message  "BadContextToken".

Mr. Google comes back with tons of results about why soapUI doesn’t play nicely with WCF and recommends WCF Storm which looks good but it’s not free.

So a whack of investigation later:

Add the following binding into the <bindings> section of your web.config:

<!-- soapUI -->
      <wsHttpBinding>
        <binding name="wsHttpBindingNoSecurity">
          <security mode="None">
            <transport clientCredentialType="None" />
            <message establishSecurityContext="false" />
          </security>
        </binding>
      </wsHttpBinding>

Add the following "bindingConfiguration” parameter to your <endpoint> section:

binding="wsHttpBinding" bindingConfiguration="wsHttpBindingNoSecurity"

The WCF service has an endpoint like:

blahblah.svc

For soapUI you need to change this to blahblah.svc?wsdl when you “Add WSDL”.

Once you’ve added the service to soapUI, click the default operation and then click the “WS-A” tab at the bottom.

Click “Enable/disable WS-A addressing”.

Click “Add default wsa:Action”.

Click “Add default wsa:To”.

And (finally) success!

REMEMBER: Every time you change the web.config, you need to right-click the soapUI service and “Update Definition” or F5!

Enjoy!

3 comments:

Anonymous said...

Thanks for the post, this worked for me.

Dario Picco said...

I follow your example but it say "BadContextToken"...
this is my web.config









Anonymous said...

Great Thanks!