Sam Sam - 2 months ago 21x
iOS Question

How to make SOAP API request and check for response in Swift

I need to make a SOAP API request and retrieve response in Swift. I am new in SOAP API and Swift. I have an API path, API Method and Input Parameters. The output is in JSON.


as i understand from your question you don't need full soap framework to make call and handle responses.In such case you should use simple xml parser and construct your own soap xml calls.

i will advise you use to use cocoapods and integrate AEXML into your project

Here it's simple xml soap format to make call

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsd="" xmlns:xsi="">
    <m:Trans xmlns:m="" soap:mustUnderstand="1">234</m:Trans>

and it how could you construct it with AEXML

let soapRequest = AEXMLDocument()
let attributes = ["xmlns:xsi" : "", "xmlns:xsd" : ""]
let envelope = soapRequest.addChild(name: "soap:Envelope", attributes: attributes)
let header = envelope.addChild(name: "soap:Header")
let body = envelope.addChild(name: "soap:Body")
header.addChild(name: "m:Trans", value: "234", attributes: ["xmlns:m" : "", "soap:mustUnderstand" : "1"])
let getStockPrice = body.addChild(name: "m:GetStockPrice")
getStockPrice.addChild(name: "m:StockName", value: "AAPL")

after than preparing your soap calls you can use any networking library