xcode 来自 WSDL 的 Objective-C 的 SOAP 客户端生成器?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28373194/
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
SOAP Client Generator for Objective-C from WSDL?
提问by kmiklas
I'm stuck on a SOAP integration project. I need to call some SOAP Web Services from an iPad app.
我被困在一个 SOAP 集成项目上。我需要从 iPad 应用程序调用一些 SOAP Web 服务。
I have the WSDL, and I need to generate the Objective-C classes to invoke the service calls.
我有WSDL,我需要生成 Objective-C 类来调用服务调用。
The Mac developer library has an "Example: Calling a SOAP Operation with HTTP Authentication", but the sample code it links to is broken (SOAP_AuthExample.dmg, 404).
Mac 开发人员库有一个“示例:使用 HTTP 身份验证调用 SOAP 操作”,但它链接到的示例代码已损坏 ( SOAP_AuthExample.dmg, 404)。
The Web Services Core Programming Guideeven says (emphasis added):
该Web服务核心编程指南甚至说,(强调):
"Currently, OS X provides no high-level supportfor extracting SOAP functions from WSDL files. You can use NSXMLParser to read a WSDL file into memory from a URL, however. It is then relatively simple to search the file for a particular method name or to find a URL associated with a service. With a bit more effort, you can extract method names, data types, and parameter names to build a SOAP call. You can then use the Web Services Core framework to make SOAP calls and parse the responses."
“目前,OS X 不提供从 WSDL 文件中提取 SOAP 函数的高级支持。但是,您可以使用 NSXMLParser 从 URL 将 WSDL 文件读入内存。然后相对简单地在文件中搜索特定的方法名称或查找与服务关联的 URL。稍加努力,您可以提取方法名称、数据类型和参数名称以构建 SOAP 调用。然后您可以使用 Web Services Core 框架进行 SOAP 调用并解析回应。”
I've also found the following three generators; however, the first is throwing an error about some missing files, the second's code generates and endless stream of ARC errors when I try to build (and a refactor is not working), and the third is paywalled.
我还发现了以下三个生成器;然而,第一个是抛出关于一些丢失文件的错误,当我尝试构建(并且重构不起作用)时,第二个代码生成和无尽的 ARC 错误流,第三个是付费墙。
Can anyone steer me in the right direction?
任何人都可以引导我朝着正确的方向前进吗?
回答by thxou
I was in your same situation a couple of months ago, and I'm currently working in an iPad app that requires to connect to a SOAP service. I already have the classes, but they are specific for my project and I'm not authorised to share it. However, I'm making a more generic Objective-C class (in any case the final solution for all the SOAP servers) to share it with the world on Github.
几个月前我遇到了与您相同的情况,我目前正在使用需要连接到 SOAP 服务的 iPad 应用程序。我已经有了这些课程,但它们是专门针对我的项目的,我无权分享。但是,我正在制作一个更通用的 Objective-C 类(无论如何都是所有 SOAP 服务器的最终解决方案),以便在 Github 上与全世界共享。
First of all you have to set the SOAP message. It has a common structure like this:
首先,您必须设置 SOAP 消息。它有一个通用的结构,如下所示:
<?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:Header>
// here comes the header information: credentials, connection information. If needed, of course
</soap:Header>
<soap:Body>
// here comes the request parameters. In my case, these parameters are related to a resource called SOAPAction (That identifies the method to be called. e.g getListOfClients). I don't know if it is the same in all servers
</soap:Body>
</soap:Envelope>
I say to you, the company for which I'm making the app, has provided me with the methods and authentication information. I don't know if this is your case, but you have here a general glance of what to do.
我告诉你,我为其开发应用程序的公司已经向我提供了方法和身份验证信息。我不知道这是否是您的情况,但您可以在这里大致了解该怎么做。
I use AFNetworking
to send the request, in this way:
我用AFNetworking
这种方式发送请求:
NSString *messageLength = [NSString stringWithFormat:@"%lu", (unsigned long)[msg length]];
NSURL *requestURL = [NSURL URLWithString:self.requestURL];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:requestURL cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:30];
[theRequest addValue:[requestURL host] forHTTPHeaderField:@"Host"];
[theRequest addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue:soapAction forHTTPHeaderField:@"SOAPAction"];
[theRequest addValue:messageLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody:[msg dataUsingEncoding:NSUTF8StringEncoding]];
// sending the request
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:theRequest];
operation.responseSerializer = [AFHTTPResponseSerializer serializer];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSString *xml = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
NSLog(@"Take the data master Yoda: %@", xml);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Bad SOAP server!. Error: %@", error.description)
}];
[[NSOperationQueue mainQueue] addOperation:operation];
self.requestURL
is the server URL, obviously. If the request was successful, then you have the server's xml response ready to parse. If not, a request error description otherwise.
self.requestURL
显然是服务器 URL。如果请求成功,则您已准备好解析服务器的 xml 响应。如果不是,则请求错误说明,否则。
This page helped me a lot to find out a solution for some issues that I encountered, and it is related to the website http://sudzc.com/that you quotes above:
该页面帮助我找到了解决我遇到的一些问题的方法,它与您在上面引用的网站http://sudzc.com/相关:
http://blog.exadel.com/working-with-ios-and-soap/
http://blog.exadel.com/working-with-ios-and-soap/
I hope this helps in any way.
我希望这有任何帮助。