Swift Soap call with SoapAction without URL

I’m struggling to understand how to call a web service in Swift that has a published SOAP action like this “urn:xmethods-notice#getNotice”.
Result is one empty key-value pair, no errors.

*I got it working in PHP like this:
   $request = "<?xml version='1.0' encoding='UTF-8' ?>
  $client = new SoapClient("https://dev.host.com/notice/v1/service.wsdl");
  $response = $client->getNotice($request);
  ...so how to transform the code above to Swift?*

The request in Swift looks like this so far:

    is_SoapMessage = "<SOAP Envelope><XML some data...></SOAP Envelope>"        
    let is_URL: String = "https://dev.host.com/notice/v1/service.wsdl"

    let lobj_Request = NSMutableURLRequest(URL: NSURL(string: is_URL)!)
    let session = NSURLSession.sharedSession()

    lobj_Request.HTTPMethod = "POST"
    lobj_Request.HTTPBody = is_SoapMessage.dataUsingEncoding(NSUTF8StringEncoding)

    let len = is_SoapMessage.characters.count
    let lenString : String = String(len)

    lobj_Request.addValue("text/xml; charset=utf-8", forHTTPHeaderField: "Content-Type")
    lobj_Request.addValue(lenString, forHTTPHeaderField: "Content-Length")
    lobj_Request.addValue("urn:xmethods-notice#getNotice", forHTTPHeaderField: "SOAPAction")

    let task = session.dataTaskWithRequest(lobj_Request, completionHandler: {data, response, error -> Void in
        print("Response: \(response)")
        let strData = NSString(data: data!, encoding: NSUTF8StringEncoding)
        print("Body: \(strData!)")

        if error != nil
            print("Error: " + error!.description)


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s