Swift中的SOAP Web服务

我正在努力研究如何使用iOS中的SOAP从Web服务传递和检索数据。 我有这个urlhttp://www.w3schools.com/webservices/tempconvert.asmx我将用它进行测试。 我尝试使用SOAPEngine,但需要许可证。 任何人都可以知道如何实现这一目的的免费库或示例代码?

我在使用SOAP的IOS Swift Call Web Service中找到了本教程,但该示例在请求时没有参数。 我想拥有像http://www.w3schools.com/xml/tempconvert.asmx?op=CelsiusToFahrenheit这样的价值

唯一缺少的是这部分:

let is_SoapMessage: String = "20" 

这是我的完整代码:

 import UIKit class ViewController: UIViewController { let is_SoapMessage: String = "cgs:Celcius>20" override func viewDidLoad() { super.viewDidLoad() let is_URL: String = "http://www.w3schools.com/xml/CelsiusToFahrenheit" let lobj_Request = NSMutableURLRequest(URL: NSURL(string: is_URL)!) let session = NSURLSession.sharedSession() //var err: NSError? lobj_Request.HTTPMethod = "POST" lobj_Request.HTTPBody = is_SoapMessage.dataUsingEncoding(NSUTF8StringEncoding) lobj_Request.addValue("www.w3schools.com", forHTTPHeaderField: "Host") lobj_Request.addValue("text/xml; charset=utf-8", forHTTPHeaderField: "Content-Type") lobj_Request.addValue(String(is_SoapMessage.characters.count), forHTTPHeaderField: "Content-Length") lobj_Request.addValue("http://www.w3schools.com/xml/CelsiusToFahrenheit", 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) } }) task.resume() } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } } 

当我需要提交20的值时,如何更改此…

提前致谢。

// Swift3我使用下面的代码修复了问题:

 var is_SoapMessage: String = "20" override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. let is_URL: String = "http://www.w3schools.com/webservices/tempconvert.asmx" let lobj_Request = NSMutableURLRequest(URL: NSURL(string: is_URL)!) let session = NSURLSession.sharedSession() //let err: NSError? lobj_Request.HTTPMethod = "POST" lobj_Request.HTTPBody = is_SoapMessage.dataUsingEncoding(NSUTF8StringEncoding) lobj_Request.addValue("www.w3schools.com", forHTTPHeaderField: "Host") lobj_Request.addValue("text/xml; charset=utf-8", forHTTPHeaderField: "Content-Type") lobj_Request.addValue(String(is_SoapMessage.characters.count), forHTTPHeaderField: "Content-Length") lobj_Request.addValue("http://www.w3schools.com/webservices/CelsiusToFahrenheit", 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) } }) task.resume() }