أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.
import UIKit
class ViewController: UIViewController {
var is_SoapMessage: String = "<soapenv:Envelope xmlns:soapenv=\\"http://schemas.xmlsoap.org/soap/envelope/\\" xmlns:cgs=\\"http://YOURURL/\\"><soapenv:Header/><soapenv:Body><cgs:PATHTOAPPENDINURL/></soapenv:Body></soapenv:Envelope>"
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.
}
@IBAction func btnClicked(sender: AnyObject)
{
var is_URL: String = "http://www.cgsapi.com/CGSWebService.asmx"
var lobj_Request = NSMutableURLRequest(URL: NSURL(string: is_URL)!)
var session = NSURLSession.sharedSession()
var err: NSError?
lobj_Request.HTTPMethod = "POST"
lobj_Request.HTTPBody = is_SoapMessage.dataUsingEncoding(NSUTF8StringEncoding)
lobj_Request.addValue("www.cgsapi.com", forHTTPHeaderField: "Host")
lobj_Request.addValue("text/xml; charset=utf-8", forHTTPHeaderField: "Content-Type")
lobj_Request.addValue(String(count(is_SoapMessage)), forHTTPHeaderField: "Content-Length")
//lobj_Request.addValue("", forHTTPHeaderField: "Content-Length")
lobj_Request.addValue("http://www.cgsapi.com/GetSystemStatus", forHTTPHeaderField: "SOAPAction")
var task = session.dataTaskWithRequest(lobj_Request, completionHandler: {data, response, error -> Void in
println("Response: \\(response)")
var strData = NSString(data: data, encoding: NSUTF8StringEncoding)
println("Body: \\(strData)")
if error != nil
{
println("Error: " + error.description)
}
})
task.resume()
}
}
Before answering, I'm going to give a brief overview for the benefit of the wider audience; experts, bear with me please :)
In short, a Web Service is an API (Application Programming Interface) which is accessible via HTTP.
SOAP stands for Simple Object Access Protocol. It is an XML-based protocol for accessing web services and allowing applications to exchange information over HTTP.
And now for the answer: how to handle SOAP in iOS. To do that from the iOS SDK, below are the steps:
Hope this helps ..