使用Soap Wcf Web服务的Swift ios

时间:2015-07-03 06:07:49

标签: ios swift

任何人都可以帮助将问题swift ios与soap对象连接起来

  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")
        }

2 个答案:

答案 0 :(得分:2)

嗯,突然出现的事情如下:

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&lt; 7.0,我怀疑。我怀疑 - 也许是假的 - 提问者是一个做Swift的C#程序员,他可能不熟悉委托模式,这在Apple的框架中很常见,但在微软的框架中并不常见。如果是这样,NSURLSession的界面将更加可口。

答案 1 :(得分:0)

问题在于肥皂envevlope映射,现在我说的是,所有的东西现在都很完美。

谢谢