title: How to connect to a Web Service (SOAP + DES) from iOS?
body: <p>I am really new to Xcode and I need to connect to a web service API (SOAP + DES), which means I have to send a Username, Password, Key and IV to the server before I can get the XML file and parse it.</p>
  
  <p>Is there any tutorial about connecting to a Web Service API (SOAP + DES) from an iPhone?</p>
  
  <pre><code>    -(IBAction)buttonClick:(id)sender
  {
      recordResults = NO;
  
      NSString *soapMessage = [NSString stringWithFormat:
       @"&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;"
       "&lt;soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance" "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema" "xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"&gt;"
       "&lt;soap:Header&gt;"
       "&lt;CredentialSoapHeader xmlns=\"http://tempuri.org/\"&gt;"
       "&lt;userID&gt;xxxxx&lt;/userID&gt;"
       "&lt;Password&gt;xxxx&lt;/Password&gt;"
       "&lt;/CredentialSoapHeader&gt;"
       "&lt;/soap:Header&gt;"
       "&lt;soap:Body&gt;"
       "&lt;GetNearUserByArticleLatLon xmlns=\"http://tempuri.org/\"&gt;"
       "&lt;strXML&gt;"
                               "&lt;XMLDATA&gt;\n"
                               "&lt;KeyWord&gt;&lt;/KeyWord&gt;\n"
                               "&lt;Lat&gt;0&lt;/Lat&gt;\n"
                               "&lt;Lon&gt;0&lt;/Lon&gt;\n"
                               "&lt;IP&gt;219.71.65.55&lt;/IP&gt;\n"
                               "&lt;CurrentPage&gt;1&lt;/CurrentPage&gt;\n"
                               "&lt;PageSize&gt;10&lt;/PageSize&gt;\n"
                               "&lt;/XMLDATA&gt;\n"
                               "&lt;/strXML&gt;"
       "&lt;/GetNearUserByArticleLatLon&gt;"
       "&lt;/soap:Body&gt;"
       "&lt;/soap:Envelope&gt;"];
  
  
      NSLog(@"%@", soapMessage);
  
      //http://www.xignite.com/services/GetRealQuote
      NSURL *url = [NSURL URLWithString:@"http://api3.mmnears.com/API/api.asmx?op=GetNearUserByArticleLatLon"];
      NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
      NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];
  
      [theRequest addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
      [theRequest addValue:@"http://tempuri.org/GetNearUserByArticleLatLon" forHTTPHeaderField:@"SOAPAction"];
      [theRequest addValue:msgLength forHTTPHeaderField:@"Content-Length"];
      [theRequest setHTTPMethod:@"POST"];
      [theRequest setHTTPBody:[soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
  
  
      NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
      NSLog(@"theConnection = %@",theConnection);
  
      if(theConnection)
      {
          webData = [[NSMutableData data] retain];
          NSLog(@"WebData = %@",webData);
  
      }
      else 
      {
          NSLog(@"theConnection is null");
      }
  
  }
  
  
  -(void)connection:(NSURLConnection*)connection didReceiveResponse:(NSURLResponse*)response
  {
      [webData setLength:0];
       NSHTTPURLResponse * httpResponse;
  
      httpResponse = (NSHTTPURLResponse *) response;
  
      NSLog(@"HTTP error %zd", (ssize_t) httpResponse.statusCode);
  
  }
  
  -(void)connection:(NSURLConnection *)connection didReceiveData:(NSData*)data
  {
      [webData appendData:data];
      NSLog(@"webdata: %@", data);
  
  }
  
  -(void)connection:(NSURLConnection *)connection didFailWithError:(NSError*)error
  {
      NSLog(@"error with the connection");
      [connection release];
      [webData release];
  }
  
  -(void)connectionDidFinishLoading:(NSURLConnection *)connection
  {
      NSLog(@"DONE. Received bytes %d", [webData length]);
      NSString *theXML = [[NSString alloc] initWithBytes:[webData mutableBytes] length:[webData length] encoding:NSUTF8StringEncoding];
      NSLog(@"xml %@",theXML);
      [theXML release];
  </code></pre>