Hello, I am new to the Swift development world and would like to know what the best way (working sample code would be beneficial) to run a web service, particularly WSDL, and then parse the XML code for display? I've scoured the internet on examples of this, but there doesn't seem to be a whole lot of examples out there, and if there were, they were written in objective c.
Parsing WSDL Web Services
I have the same problem as well, a third party developer published a web service with its WSDL. I am trying to consume a method of the service. I used some testing tools and I know that web service is working as SOAPUi gives me expected results, but I cannot figure out how to develop a working SOAP call in Swift from the published web service and its WSDL.
Any help or example of how to consume web service through WSDL in Swift would be appreciated?
I have the same problem too, someone found a solution?
Hi
I have tried an example
import UIKit
class ViewController: UIViewController , NSXMLParserDelegate{
var is_SoapMessage: String = "<soapenv:Envelope xmlns:soapenv=\"http:/
/
var is_SoapMessage = "<?xml version='1.0' encoding='UTF-8'?><soap:Envelope xmlns:soap=' */
var myelement :String = ""
var elementValue: String?
var success = false
@IBAction func makeAction(sender: AnyObject) {
var is_URL: String = "http:/
var lobj_Request = NSMutableURLRequest(URL: NSURL(string: is_URL)!)
var session = NSURLSession.sharedSession()
var err: NSError?
lobj_Request.HTTPMethod = "POST"
lobj_Request.HTTPBody = is_SoapMessage.dataUsingEncoding(NSUTF8StringEncoding)
lobj_Request.addValue("www.cgsapi.com", forHTTPHeaderField: "Host")
lobj_Request.addValue("text/xml; charset=utf-8", forHTTPHeaderField: "Content-Type")
lobj_Request.addValue(String(count(is_SoapMessage)), forHTTPHeaderField: "Content-Length")
/
lobj_Request.addValue("http:/
var task = session.dataTaskWithRequest(lobj_Request, completionHandler: {data, response, error -> Void in
println("Response: \(response)")
var strData = NSString(data: data, encoding: NSUTF8StringEncoding)
/
let parser = NSXMLParser(data: data)
parser.delegate = self
parser.parse()
/
if error != nil
{
println("Error: " + error.description)
}
})
task.resume()
}
func parser(parser: NSXMLParser, didStartElement elementName: String, namespaceURI: String?, qualifiedName qName: String?, attributes attributeDict: [NSObject : AnyObject]) {
println("first case ")
println(elementName)
if elementName == "GetSystemStatusResult" {
elementValue = String()
}
}
func parser(parser: NSXMLParser, foundCharacters string: String?) {
println("second case ")
println(string)
if elementValue != nil {
elementValue! += string!
}
}
func parser(parser: NSXMLParser, didEndElement elementName: String, namespaceURI: String?, qualifiedName qName: String?
) {
println("third case ")
if elementName == "GetSystemStatusResult" {
if elementValue == "true" {
success = true
println("this is right answer ")
}
elementValue = nil
}
}
override func viewDidLoad() {
super.viewDidLoad()
/
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
/
}
}
it give complete parsing .
but this is asmx service I try to make an example wcf (svc)
Thanks
This is
var is_SoapMessage: String = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:cgs=\"http://www.cgsapi.com/\"><soapenv:Header/><soapenv:Body><cgs:GetSystemStatus/></soapenv:Body></soapenv:Envelope>"
soap message of above example which need to match .
Found an answer from edwardmp on stackoverflow http://stackoverflow.com/questions/30739149/how-do-i-accept-a-self-signed-ssl-certificate-using-ios-7s-nsurlsessionand a example https://gist.github.com/edwardmp/df8517aa9f1752e73353 that worked. I struggled for awhile trying to get this