SOAP request with URLSession not parsed?!

Dear all,


I am trying to use a SOAP Webinterface with Swift 3 and XCode 8 in an app.


This code is used to get the SOAP request executed and I do receive the response but I can not get it over to the XMLParser ?!?!?


See for yourself:


————————– Code ———————–


@IBAction func Btn_search(_ sender: UIButton) {



    […… setting up SOAP Message here …..] 



    let theRequest = NSMutableURLRequest(url: soapURL)

        let msgLength = soapMessage.characters.count

        theRequest.setValue(“Basic (base64LoginString)”, forHTTPHeaderField: “Authorization”)

        theRequest.addValue(“text/xml”, forHTTPHeaderField: “Content-Type”)

        theRequest.addValue(“””, forHTTPHeaderField: “SOAPAction”)

        theRequest.addValue(String(msgLength), forHTTPHeaderField: “Content-Length”)

        theRequest.httpMethod = “POST”

        theRequest.httpBody = String.Encoding.utf8, allowLossyConversion: false)


        let session = URLSession.shared


        let task = session.dataTask(with: theRequest as URLRequest, completionHandler: { (data, response, error) in

            guard error == nil && data != nil else {

                print(“Connection error or data is nil !”)




            if response != nil {

                self.mutableData.length = 0



            let dataString = NSString(data: data!, encoding: String.Encoding.utf8.rawValue)











    func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: Error?) {


    print(“Entered urlSession did Complete”)


    let XMLparser = XMLParser(data: mutableData as Data)

        XMLparser.delegate = self


        XMLparser.shouldResolveExternalEntities = true



————————– /Code ———————–


print(dataString) is done and I can see the full XML return from the SOAP Call but the print(“Entered ….”) statement is never called?!?!


Any ideas?


Thanks in advance


Best regards


Powered by WPeMatico


You may also like...

Comments are closed.