title: Recieving SOAP error when requesting a WCF Web Service in Objective C (iOS App)
body: <p>I am trying to call a web service from an iOS app. I have developed that service in WCF. The web service is hosted on IIS configured with BasicHTTPBinding. I have developed a simple iOS app that calls that web service hosted on a remote PC. </p>
  
  <p>The iOS app is working fine but the SOAP service doesn't seem to understand the request I am sending from the iOS app. Here are all the details, the error I get is at the end.</p>
  
  <p>The WSDL of web service is:</p>
  
  <pre><code>    &lt;wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" xmlns:wsa10="http://www.w3.org/2005/08/addressing" xmlns:tns="http://tempuri.org/" 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:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" name="SLService" targetNamespace="http://tempuri.org/"&gt;
  &lt;wsdl:types&gt;
  &lt;xsd:schema targetNamespace="http://tempuri.org/Imports"&gt;
  &lt;xsd:import schemaLocation="http://10.211.55.4/TestService/SLService.svc?xsd=xsd0" namespace="http://tempuri.org/"/&gt;
  &lt;xsd:import schemaLocation="http://10.211.55.4/TestService/SLService.svc?xsd=xsd1" namespace="http://schemas.microsoft.com/2003/10/Serialization/"/&gt;
  &lt;/xsd:schema&gt;
  &lt;/wsdl:types&gt;
  &lt;wsdl:message name="ISLService_DoWork_InputMessage"&gt;
  &lt;wsdl:part name="parameters" element="tns:DoWork"/&gt;
  &lt;/wsdl:message&gt;
  &lt;wsdl:message name="ISLService_DoWork_OutputMessage"&gt;
  &lt;wsdl:part name="parameters" element="tns:DoWorkResponse"/&gt;
  &lt;/wsdl:message&gt;
  &lt;wsdl:portType name="ISLService"&gt;
  &lt;wsdl:operation name="DoWork"&gt;
  &lt;wsdl:input wsaw:Action="http://tempuri.org/ISLService/DoWork" message="tns:ISLService_DoWork_InputMessage"/&gt;
  &lt;wsdl:output wsaw:Action="http://tempuri.org/ISLService/DoWorkResponse" message="tns:ISLService_DoWork_OutputMessage"/&gt;
  &lt;/wsdl:operation&gt;
  &lt;/wsdl:portType&gt;
  &lt;wsdl:binding name="BasicHttpBinding_ISLService" type="tns:ISLService"&gt;
  &lt;soap:binding transport="http://schemas.xmlsoap.org/soap/http"/&gt;
  &lt;wsdl:operation name="DoWork"&gt;
  &lt;soap:operation soapAction="http://tempuri.org/ISLService/DoWork" style="document"/&gt;
  &lt;wsdl:input&gt;
  &lt;soap:body use="literal"/&gt;
  &lt;/wsdl:input&gt;
  &lt;wsdl:output&gt;
  &lt;soap:body use="literal"/&gt;
  &lt;/wsdl:output&gt;
  &lt;/wsdl:operation&gt;
  &lt;/wsdl:binding&gt;
  &lt;wsdl:service name="SLService"&gt;
  &lt;wsdl:port name="BasicHttpBinding_ISLService" binding="tns:BasicHttpBinding_ISLService"&gt;
  &lt;soap:address location="http://10.211.55.4/TestService/SLService.svc"/&gt;
  &lt;/wsdl:port&gt;
  &lt;/wsdl:service&gt;
  &lt;/wsdl:definitions&gt;
  </code></pre>
  
  <p>Here is how I am making the SOAP request in iOS, the problem is most probably here:</p>
  
  <pre><code>NSString *soapMessage = [NSString stringWithFormat:@"&lt;SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"&gt;&lt;SOAP-ENV:Body&gt;&lt;DoWork&gt;&lt;/DoWork&gt;&lt;/SOAP-ENV:Body&gt;&lt;/SOAP-ENV:Envelope&gt;"];
  
  NSURL *url=[NSURL URLWithString:@"http://10.211.55.4/TestService/SLService.svc/"];
  
  NSMutableURLRequest *theRequest= [NSMutableURLRequest requestWithURL:url];
  
  NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];
  
  [theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
  [theRequest addValue: @"urn:SLService/DoWork" forHTTPHeaderField:@"SOAPAction"];
  [theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
  [theRequest setHTTPMethod:@"POST"];    
  [theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
  
  NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
  
  if (theConnection) {
  
      responseData = [[NSMutableData data] retain];
  } else {
  
      messageTextView.text=@"Failed";
  
  }
  </code></pre>
  
  <p>Here is what's inside the WCF Web Service class:</p>
  
  <pre><code>namespace TestSilverlight.Web{
  
  public class SLService : ISLService
  {
      public string DoWork()
      {
          return "Service Works!";
      }
  }}
  </code></pre>
  
  <p>Here is the content of web.config file in WCF web service:</p>
  
  <pre><code>    &lt;?xml version="1.0"?&gt;
  
  &lt;!--
    For more information on how to configure your ASP.NET application, please visit
    http://go.microsoft.com/fwlink/?LinkId=169433
    --&gt;
  
  &lt;configuration&gt;
      &lt;system.web&gt;
          &lt;compilation debug="true" targetFramework="4.0" /&gt;
      &lt;/system.web&gt;
  
      &lt;system.serviceModel&gt;
          &lt;behaviors&gt;
              &lt;serviceBehaviors&gt;
                  &lt;behavior name=""&gt;
                      &lt;serviceMetadata httpGetEnabled="true" /&gt;
                      &lt;serviceDebug includeExceptionDetailInFaults="false" /&gt;
                  &lt;/behavior&gt;
              &lt;/serviceBehaviors&gt;
          &lt;/behaviors&gt;
          &lt;serviceHostingEnvironment multipleSiteBindingsEnabled="true" /&gt;
      &lt;/system.serviceModel&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>Here is the SOAP response (error) I get in the responseData object:</p>
  
  <blockquote>
    <p>a:ActionNotSupportedThe message with Action 'urn:ISLService/DoWork' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver.  Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None).</p>
  </blockquote>
  
  <p>I suck at asking questions here, I hope you guys understand this one. Please help.</p>