我試圖建立我的第一個應用迅速和我有,當我試圖消耗SOAP Web服務的麻煩.. 下面是方法:迅速Web服務通信
@IBAction FUNC callWebService(發件人: AnyObject){
var userName:NSString = "abc"
var password:NSString = "def"
var soapMsg = "<?xml version='1.0' encoding='UTF-8'?><soap:Envelope xmlns:xsi='http://87.106.20.80:8080/axis2/services/app2beeService?wsdl' xmlns:xsd='http://localhost:8080/beeSmartWS' xmlns:soap='http:/bee.myservice.com/userLogin'><soap:Body><userLogin xmlns 'http://87.106.20.80:8080/axis2/services/app2beeService?wsdl/userLogin><:userId>" + userName + "</userId><password>" + password + "</password></userLogin></soap:Body></soap:Envelope>"
//let soapAction = "http://bee.myservice.com/userLogin"
//let urlString = "http://bee.myservice.com/"
let urlString: String = "http://bee.myservice.com/"
var url: NSURL = NSURL(string: urlString)!
//var request: NSURLRequest = NSURLRequest(URL: url)
var request = NSMutableURLRequest(URL: url)
var msgLength = String(countElements(soapMsg))
request.HTTPMethod = "POST"
request.HTTPBody = soapMsg.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)
request.addValue("text/xml; charset=utf-8", forHTTPHeaderField: "Content-Type")
request.addValue(msgLength, forHTTPHeaderField: "Content-Length")
request.addValue("http://bee.myservice.com/userLogin", forHTTPHeaderField: "Action")
var connection: NSURLConnection = NSURLConnection(request: request, delegate: self, startImmediately: true)!
connection.start()
println(request)
var response: NSURLResponse?
var data = NSURLConnection.sendSynchronousRequest(request, returningResponse: &response, error: nil) as NSData?
if let httpResponse = response as? NSHTTPURLResponse {
println("error \(httpResponse.statusCode)")
println(response)
}
}
}
我沒有得到任何迴應,當我遇到這個請求
Web服務的詳細信息發送: Web服務類型:Axis2中(Java和基於SOAP) Web服務的WSDL鏈接:http://87.106.20.80:8080/axis2/services/app2beeService?wsdl目標命名空間:http://bee.myservice.com SOAP動作:添加/ USERLOGIN目標命名空間
你得到一個錯誤代碼?注意:NSURLSession比舊的NSURLConnection更可取。你不需要使用Alamofire,但是你應該使用NSURLSession。 –
當我使用我的本地機器(http:// localhost:8080/beeSmartWS /)上運行的web服務的url但其他url(目標名稱空間)返回錯誤代碼500 – pioneerhear