title: How do I call a SOAP web service in Swift 2?
body: <p>I want to call web service for Swift 2. But it never works. This is my code.</p>
  
  <pre><code>import UIKit
  
  class ViewController: UIViewController, UITextFieldDelegate, NSURLConnectionDelegate, NSXMLParserDelegate {
  
      var mutableData:NSMutableData  = NSMutableData.init()
      var currentElementName:NSString = ""
  
  
  
      @IBOutlet var txtCelsius : UITextField!
      @IBOutlet var txtFahrenheit : UITextField!
  
  
      @IBAction func actionConvert(sender : AnyObject) {
          let celcius = txtCelsius.text
  
          let soapMessage = "&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:Body&gt;&lt;CelsiusToFahrenheit xmlns='http://www.w3schools.com/xml/'&gt;&lt;Celsius&gt;\(celcius)&lt;/Celsius&gt;&lt;/CelsiusToFahrenheit&gt;&lt;/soap:Body&gt;&lt;/soap:Envelope&gt;"
  
  
          let urlString = "http://www.w3schools.com/xml/tempconvert.asmx"
  
          let url = NSURL(string: urlString)
  
          let theRequest = NSMutableURLRequest(URL: url!)
  
  
          theRequest.addValue("text/xml; charset=utf-8", forHTTPHeaderField: "Content-Type")
          theRequest.addValue((soapMessage), forHTTPHeaderField: "Content-Length")
          theRequest.HTTPMethod = "POST"
          theRequest.HTTPBody = soapMessage.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false) // or false
  
          let connection = NSURLConnection(request: theRequest, delegate: self, startImmediately: true)
          connection!.start()
  
  
      }
  
  
  
  
      override func viewDidLoad() {
          super.viewDidLoad()
          // Do any additional setup after loading the view, typically from a nib.
      }
  
      override func didReceiveMemoryWarning() {
          super.didReceiveMemoryWarning()
          // Dispose of any resources that can be recreated.
      }
  
  
  
      func connection(connection: NSURLConnection!, didReceiveResponse response: NSURLResponse!) {
          mutableData.length = 0;
      }
  
      func connection(connection: NSURLConnection!, didReceiveData data: NSData!) {
          mutableData.appendData(data)
      }
  
  
      func connectionDidFinishLoading(connection: NSURLConnection!) {
          let xmlParser = NSXMLParser(data: mutableData)
          xmlParser.delegate = self
          xmlParser.parse()
          xmlParser.shouldResolveExternalEntities = true
  
      }
  
  
      func parser(parser: NSXMLParser, foundCharacters string: String) {
          if currentElementName == "CelsiusToFahrenheit" {
              txtFahrenheit.text = string
          }
      }
  </code></pre>