title: How to connect to a web service using NSURLSession with Delegate methods?
body: <p>I am taking a stab at connecting to web services in iOS and I am running into a lot of problems. I found a practice web service here - <a href="http://www.w3schools.com/webservices/tempconvert.asmx?op=CelsiusToFahrenheit" rel="nofollow">http://www.w3schools.com/webservices/tempconvert.asmx?op=CelsiusToFahrenheit</a> </p>
  
  <p>I have written this code out so far</p>
  
  <pre><code>    let soapMessage = "&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\n"
      "&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;\n"
      "&lt;soap:Body&gt;\n"
      "&lt;CelsiusToFahrenheit xmlns=\"http://www.w3schools.com/webservices/\"&gt;\n"
      "&lt;Celsius&gt;50&lt;/Celsius&gt;\n"
      "&lt;/CelsiusToFahrenheit&gt;\n"
      "&lt;/soap:Body&gt;\n"
      "&lt;/soap:Envelope&gt;\n"
  
      let url = NSURL(string: "http://w3schools.com/webservices/tempconvert.asmx")!
  
      var request = NSMutableURLRequest(URL: url)
  
      let messageLength = "\(soapMessage.utf16Count)"
      NSLog("\(messageLength)")
      request.addValue("text/xml; charset=utf-8", forHTTPHeaderField: "Content-Type")
      request.addValue("http://www.w3schools.com/webservices/CelsiusToFahrenheit", forHTTPHeaderField: "SOAPAction")
      request.addValue(messageLength, forHTTPHeaderField: "Content-Length")
      request.HTTPMethod = "POST"
      request.HTTPBody = soapMessage.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)
  
      var urlSession: NSURLSession = NSURLSession(configuration: NSURLSessionConfiguration.defaultSessionConfiguration(), delegate: self, delegateQueue: NSOperationQueue.mainQueue())
  </code></pre>
  
  <p>It works to connect but my response comes back as as text/html and not text/xml. My question is why is it returning incorrectly? Also do I use a NSURLSessionDataTask or NSURLSessionDownloadTask?</p>