How to access SOAP services from iPhone

后端 未结 7 1214
无人共我
无人共我 2020-11-22 09:34

I\'m planning to develop an app for the iPhone and that app would have to access a couple of SOAP services. While doing some basic checking in the iPhone SDK I was not able

相关标签:
7条回答
  • 2020-11-22 10:00

    I've historically rolled my own access at a low level (XML generation and parsing) to deal with the occasional need to do SOAP style requests from Objective-C. That said, there's a library available called SOAPClient (soapclient) that is open source (BSD licensed) and available on Google Code (mac-soapclient) that might be of interest.

    I won't attest to it's abilities or effectiveness, as I've never used it or had to work with it's API's, but it is available and might provide a quick solution for you depending on your needs.

    Apple had, at one time, a very broken utility called WS-MakeStubs. I don't think it's available on the iPhone, but you might also be interested in an open-source library intended to replace that - code generate out Objective-C for interacting with a SOAP client. Again, I haven't used it - but I've marked it down in my notes: wsdl2objc

    0 讨论(0)
  • 2020-11-22 10:01

    My solution was to have a proxy server accept REST, issue the SOAP request, and return result, using PHP.

    Time to implement: 15-30 minutes.

    Not most elegant, but solid.

    0 讨论(0)
  • 2020-11-22 10:03

    You can connect using a tool that I found http://www.wsdl2code.com

    SampleServiceProxy *proxy = [[SampleServiceProxy alloc]initWithUrl:@"YOUR
            URL" AndDelegate:self];
    
    [proxy GetDouble];
    [proxy GetEnum];
    [proxy getEnum:kTestEnumTestEnum2];
    [proxy GetInt16];
    [proxy GetInt32];
    [proxy GetInt64];
    [proxy GetString];
    [proxy getListStrings];
    
    0 讨论(0)
  • 2020-11-22 10:13

    Have a look at here this link and their roadmap. They have RO|C on the way, and that can connect to their web services, which probably includes SOAP (I use the VCL version which definitely includes it).

    0 讨论(0)
  • 2020-11-22 10:21

    One word: Don't.

    OK obviously that isn't a real answer. But still SOAP should be avoided at all costs. ;-) Is it possible to add a proxy server between the iPhone and the web service? Perhaps something that converts REST into SOAP for you?

    You could try CSOAP, a SOAP library that depends on libxml2 (which is included in the iPhone SDK).

    I've written my own SOAP framework for OSX. However it is not actively maintained and will require some time to port to the iPhone (you'll need to replace NSXML with TouchXML for a start)

    0 讨论(0)
  • 2020-11-22 10:21

    Here is a swift 4 sample code which execute API calling using SOAP service format.

       func callSOAPWSToGetData() {
    
            let strSOAPMessage =
                "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
                    "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
                    "<soap:Body>" +
                    "<CelsiusToFahrenheit xmlns=\"http://www.yourapi.com/webservices/\">" +
                    "<Celsius>50</Celsius>" +
                    "</CelsiusToFahrenheit>" +
                    "</soap:Body>" +
            "</soap:Envelope>"
    
            guard let url = URL.init(string: "http://www.example.org") else {
                return
            }
            var request = URLRequest.init(url: url)
            let length = (strSOAPMessage as NSString).length
            request.addValue("application/soap+xml; charset=utf-8", forHTTPHeaderField: "Content-Type")
            request.addValue("http://www.yourapi.com/webservices/CelsiusToFahrenheit", forHTTPHeaderField: "SOAPAction")
            request.addValue(String(length), forHTTPHeaderField: "Content-Length")
            request.httpMethod = "POST"
            request.httpBody = strSOAPMessage.data(using: .utf8)
    
            let config = URLSessionConfiguration.default
            let session = URLSession(configuration: config)
            let task = session.dataTask(with: request) { (data, response, error) in
                guard let responseData = data else {
                    print("Error: did not receive data")
                    return
                }
                guard error == nil else {
                    print("error calling GET on /todos/1")
                    print(error ?? "")
                    return
                }
                print(responseData)
                let strData = String.init(data: responseData, encoding: .utf8)
                print(strData ?? "")
            }
            task.resume()
        }
    
    0 讨论(0)
提交回复
热议问题