ios 如何从 iPhone 访问 SOAP 服务
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/204465/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to access SOAP services from iPhone
提问by Gero
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.
我计划为 iPhone 开发一个应用程序,该应用程序必须访问几个 SOAP 服务。在 iPhone SDK 中进行一些基本检查时,我找不到任何支持访问 SOAP 服务的方法,通过谷歌搜索得出的结论是 iPhone SDK 中不支持 SOAP。
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?
因此,如果我确实想要构建该应用程序,我将需要想出一种从 iPhone 访问 SOAP 服务的方法。最好的方法是什么?任何最佳实践?是否有人已经使用 iPhone SDK 中提供的功能编写了一个库来访问 SOAP 服务?
(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).
(因为我需要访问的服务是由另一方公开的,他们只将其公开为 SOAP,不幸的是,切换到另一种类型的接口(例如基于 REST 的 API)不是一个选项。
Gero
下吕
回答by schwa
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?
好吧,显然这不是一个真正的答案。但是仍然应该不惜一切代价避免使用 SOAP。;-) 是否可以在 iPhone 和 Web 服务之间添加代理服务器?也许可以为您将 REST 转换为 SOAP?
You couldtry CSOAP, a SOAP library that depends on libxml2 (which is included in the iPhone SDK).
您可以尝试CSOAP,这是一个依赖于 libxml2(包含在 iPhone SDK 中)的 SOAP 库。
I've written my own SOAP frameworkfor OSX. However it is not actively maintained and will require some time to port to the iPhone (you'll need to replace NSXML with TouchXMLfor a start)
我已经为 OSX编写了自己的SOAP 框架。但是它不积极维护,将需要一些时间来港的iPhone(你需要替换NSXML TouchXML一开始)
回答by davidjhinson
My solution was to have a proxy server accept REST, issue the SOAP request, and return result, using PHP.
我的解决方案是让代理服务器接受 REST,发出 SOAP 请求,并使用 PHP 返回结果。
Time to implement: 15-30 minutes.
实施时间:15-30分钟。
Not most elegant, but solid.
不是最优雅,但坚固。
回答by heckj
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.
过去,我一直在低级别(XML 生成和解析)进行自己的访问,以处理来自 Objective-C 的 SOAP 样式请求的偶尔需要。也就是说,有一个名为 SOAPClient ( soapclient) 的可用库,它是开源的(BSD 许可),并且可以在可能感兴趣的Google Code ( mac-soapclient) 上使用。
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.
我不会证明它的能力或有效性,因为我从未使用过它或不得不使用它的 API,但它是可用的,并且可能会根据您的需要为您提供快速解决方案。
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
Apple 曾经有一个非常糟糕的实用程序,称为 WS-MakeStubs。我不认为它在 iPhone 上可用,但您可能也对旨在取代它的开源库感兴趣 - 代码生成用于与 SOAP 客户端交互的 Objective-C。同样,我还没有使用它 - 但我已经在我的笔记中标记了它:wsdl2objc
回答by Bennya
You can connect using a tool that I found http://www.wsdl2code.com
您可以使用我找到的工具进行连接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];
回答by Tech
Here is a swift 4sample code which execute API calling using SOAP service format.
这是一个使用 SOAP 服务格式执行 API 调用的swift 4示例代码。
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()
}
回答by Dr. Alex RE
Have a look at gsoapthat includes two iOS examples in the download package under ios_plugin. The tool converts WSDL to code for SOAP and XML REST.
看看在ios_plugin下的下载包中包含两个 iOS 示例的 gsoap。该工具将 WSDL 转换为 SOAP 和 XML REST 的代码。
回答by mj2008
Have a look at here this linkand 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).
在这里查看此链接及其路线图。他们有 RO|C,可以连接到他们的 Web 服务,其中可能包括 SOAP(我使用的 VCL 版本肯定包括它)。