【发布时间】:2015-08-24 19:46:44
【问题描述】:
我正在尝试构建我的第一个 swift 应用程序,但在尝试使用soap Web 服务时遇到了问题。 方法如下:
@IBAction func callWebService(sender: 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 服务类型: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。
-
当我使用在本地机器上运行的 web 服务的 url (localhost:8080/beeSmartWS) 时,我得到一个 http 错误代码 200,但另一个 url(目标命名空间)返回错误代码 500
标签: ios web-services swift soap