title: SOAP in iOS Application
body: <p>I'm trying to develop an app that uses data from a SOAP service. is the first time I use a SOAP service. After reading several tutorials I thought I would be able to set the request to the service in the right way but I always get errors in the response. What's wrong ?!</p>
  
  <pre><code>NSString *soapMessage = [NSString stringWithFormat:@"&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\n"
                   "&lt;env:Envelope xmlns:env=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:ns1=\"urn:Lottery.Intf-ILottery\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:enc=\"http://www.w3.org/2003/05/soap-encoding\"&gt;\n"
                   "&lt;env:Body&gt;\n"
                   "&lt;ns1:GetUpcomingLotteries env:encodingStyle=\"http://www.w3.org/2003/05/soap-encoding\"&gt;\n"
                   "&lt;EntityID xsi:type=\"xsd:int\"&gt;2&lt;/EntityID&gt;\n"
                   "&lt;Password xsi:type=\"xsd:string\"&gt;Smart@Winners&lt;/Password&gt;\n"
                   "&lt;SortBy xsi:type=\"xsd:int\"&gt;0&lt;/SortBy&gt;\n"
                   "&lt;limit xsi:type=\"xsd:int\"&gt;0&lt;/limit&gt;\n"
                   "&lt;/ns1:GetUpcomingLotteries&gt;\n"
                   "&lt;/env:Body&gt;\n"
                   "&lt;/env:Envelope&gt;"];
  
  
  NSURL *sRequestURL = [NSURL URLWithString:@"xxxxxxxxx"];
  NSMutableURLRequest *myRequest = [NSMutableURLRequest requestWithURL:sRequestURL];
  NSString *sMessageLength = [NSString stringWithFormat:@"%d", [soapMessage length]];
  
  [myRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
  [myRequest addValue: @"urn:Lottery.Intf-ILottery/GetUpcomingLotteries" forHTTPHeaderField:@"SOAPAction"];
  [myRequest addValue: sMessageLength forHTTPHeaderField:@"Content-Length"];
  
  [myRequest setHTTPMethod:@"POST"];
  [myRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
  
  NSError *error;
  NSURLResponse *response;
  NSData *urlData=[NSURLConnection sendSynchronousRequest:myRequest returningResponse:&amp;response error:&amp;error];
  NSString *str=[[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding];
  </code></pre>