By Gero


2008-10-15 12:07:17 8 Comments

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 to find any support for accessing SOAP services, a bit of Googling lead to the conclusion that there is no support for SOAP in the iPhone SDK.

So if I do want to build that app I'll need to come up with a approach to access SOAP services from the iPhone. What would be the best approach? Any best practices? Did someone already write a library using the functionality that is present in the iPhone SDK to access SOAP services?

(Since the service I need to access is exposed by another party and they only expose it as SOAP, it's unfortunately not an option to switch to another type of interface (e.g. REST based API).

Gero

7 comments

@Tech 2017-12-25 14:42:03

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

@Dr. Alex RE 2016-02-28 14:53:14

Have a look at gsoap that includes two iOS examples in the download package under ios_plugin. The tool converts WSDL to code for SOAP and XML REST.

@Bennya 2013-01-29 15:53:48

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];

@heckj 2008-10-15 18:14:36

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

@Gero 2008-10-18 18:18:24

Thanks, I tried to use wsdl2objc. The generation of ObjectiveC code from the WSDL works, but is (as expected) does not directly compile against iPhone SDK. I tried to tweak the sources a bit, but ended up with a bunch of errors I could not resolve

@mj2008 2008-10-15 12:34:40

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).

@davidjhinson 2008-12-22 14:04:37

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.

@Spring 2011-06-20 11:52:56

How did you that? any documents. tnx

@gdbj 2015-09-24 16:14:22

I love the mysterious non-answer. how was this upvoted?

@Magic Octopus Urn 2017-04-24 17:46:11

@gdbj because a 1:1 conversion between REST and SOAP should be self-explanitory...

@gdbj 2017-04-24 18:23:21

That's the What, but doesn't answer the question of How, which is why people come here. I'm still curious on the answer on what the implementation would be here, particularly if it is so simple.

@schwa 2008-10-15 16:17:19

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)

@WillF 2009-06-16 17:19:13

Can you elaborate on this statement "But still SOAP should be avoided at all costs"

@senfo 2010-02-25 20:30:37

If you don't mind, I'd really like an explanation to go along with this response. Also, when you say "converts REST into SOAP for you" I think you meant convert JSON into SOAP. Is this correct?

@Erik Hermansen 2010-05-03 17:55:56

Yeah, also wanting the explanation. If you just say "Don't", I want to know if you are basing it on something specific you know about iPhone/SOAP problems. On the other hand, if it's just the normal, general reasons for avoiding SOAP, I can Google "SOAP vs REST" and get a firehose mouthful of that.

@Anthony Main 2010-09-03 12:47:14

Just cause soap is not necessarily appropriate doesnt mean its not right in his implementation, there are needs that go beyond best practive more often than not

@DougW 2010-10-20 17:15:12

@schwa - Downvoted for posting a potentially useful answer with absolutely no supporting evidence or defense.

@Petesh 2010-11-23 10:42:36

This is the technical equivalent of "Don't use it because It's not provided by default" - There is no real technical reason why you should not use SOAP or any other mechanism that is provided by a service.

@jer 2011-10-23 15:57:43

Upvoted because it's absolutely right. The benefits of using SOAP outweigh its costs in terms of complexity, overhead, etc., when compared with other methods available.

@Jan Lehnardt 2011-10-23 16:04:44

Upvoted, do not use SOAP. Trust us on this one.

@Mark Sands 2011-10-23 17:20:39

@Vineel Shah 2012-10-03 15:36:33

Here's at least an answer-- SOAP is a very high-overhead protocol compared to REST. All the namespacing and validity checking and such adds a ton of extra characters to your message, and this is exactly what you want to avoid over a high-latency, potentially slow network, such as 3G. If you can guarantee that your app will only be used in a 4g environment with excellent signal, or only in Wifi, it might be more approriate. But in general with mobile networking, less is more.

@bvanvelsen 2013-09-13 11:49:18

Sometimes you simply cannot avoid using SOAP. For instance you are building an iOS or Android client, connecting to a SOAP webservice, if you have no control over the service, then you must provide a SOAP implementation.

Related Questions

Sponsored Content

14 Answered Questions

[SOLVED] Representational state transfer (REST) and Simple Object Access Protocol (SOAP)

  • 2008-10-16 19:24:14
  • Vicky
  • 267604 View
  • 704 Score
  • 14 Answer
  • Tags:   rest soap

9 Answered Questions

14 Answered Questions

[SOLVED] SOAP vs REST (differences)

4 Answered Questions

26 Answered Questions

[SOLVED] How to call a SOAP web service on Android

8 Answered Questions

[SOLVED] Why do we need RESTful Web Services?

28 Answered Questions

[SOLVED] SOAP or REST for Web Services?

0 Answered Questions

How to access WCF soap service in iphone?

2 Answered Questions

[SOLVED] Using Soap Web Services in iPhone with wsdl2objc?

4 Answered Questions

[SOLVED] which service response is good for iphone development?

Sponsored Content