Swift ios with Soap Wcf Web service



任何人都可以帮助将问题快速iOS与肥皂对象连接

  var soapMessage = "<?xml version='1.0' encoding='UTF-8'?><soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema'><soap:Body> <BindCategory xmlns=‘http://tempuri.org/'></BindCategory></soap:Body></soap:Envelope>"

        var urlString = "http://assetwebservice.sudesi.in/service.svc"
        var msgLength = String(count(soapMessage))
        var url = NSURL(string: urlString)!
        var theRequest = NSMutableURLRequest(URL: url)
        theRequest.addValue("text/xml; charset=utf-8", forHTTPHeaderField: "Content-Type")
        theRequest.addValue("http://tempuri.org/IService/BindCategory", forHTTPHeaderField: "Soapaction")
        theRequest.addValue(msgLength, forHTTPHeaderField: "Content-Length")
        theRequest.HTTPMethod = "POST"
        theRequest.HTTPBody = soapMessage.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)

        var connection = NSURLConnection(request: theRequest, delegate: self,startImmediately: true)
        connection?.start()
        if (connection == true) {
            println("Connection success")
            var mutableData : Void = NSMutableData.initialize()
        }else{
            println("Error in connection")
        }

好吧,我跳出的东西如下:

if (connection == true) {
    println("Connection success")
    // What does this line mean? I can't make sense of it.
    var mutableData : Void = NSMutableData.initialize()
}

您正在将NSURLConnection?Bool进行比较。这永远不会是真的。此外,这不是确定连接是否成功的正确方法。 NSURLConnection有一个可选的初始值设定项,以便它可以检查其参数是否有效,而不是确定连接是否成功。成功将由对委托的相应回调决定。

您应该考虑使用NSURLSession而不是NSURLConnection,除非您必须支持iOS <7.0,我对此表示怀疑。我怀疑(也许是错误的(提问者是一个做 Swift 的 C# 程序员,他可能不熟悉委托模式,这在 Apple 的框架中很常见,但在Microsoft的框架中根本不常见。如果是这样,NSURLSession 的界面将更加可口。

问题出在肥皂映射中,现在我已经纠正了,现在一切都很完美。

谢谢

最新更新