繁体   English   中英

带有Soap Wcf Web服务的Swift ios

[英]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有一个可选的初始化程序,以便它可以检查其参数是否有效,而不是这样,以便确定连接是否成功。 成功将取决于对委托的适当回调。

除非必须支持iOS <7.0,否则您应该研究使用NSURLSession而不是NSURLConnection 我怀疑-也许是错误的-发问者是一位使用Swift的C#程序员,他也许不熟悉委托模式,该委托模式在Apple框架中很常见,而在Microsoft框架中却根本不常见。 如果是这样, NSURLSession的界面将更加可口。

问题在于肥皂信封贴图,现在我已经正确地说,所有东西现在都是完美的。

谢谢

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM