【问题标题】:SOAP Client Generator for Objective-C from WSDL?来自 WSDL 的 Objective-C 的 SOAP 客户端生成器?
【发布时间】:2015-02-06 19:21:16
【问题描述】:

我被困在一个 SOAP 集成项目上。我需要从 iPad 应用程序调用一些 SOAP Web 服务。

我有 WSDL,我需要生成 Objective-C 类来调用服务调用。

Mac 开发人员库有一个 "Example: Calling a SOAP Operation with HTTP Authentication",但它链接的示例代码已损坏 (SOAP_AuthExample.dmg, 404)。

Web Services Core Programming Guide 甚至说(强调):

“目前,OS X不提供高级支持来从 WSDL 文件中提取 SOAP 函数。但是,您可以使用 NSXMLParser 将 WSDL 文件从 URL 读取到内存中。相对而言简单地在文件中搜索特定方法名称或查找与服务关联的 URL。稍加努力,您可以提取方法名称、数据类型和参数名称来构建 SOAP 调用。然后您可以使用 Web用于进行 SOAP 调用和解析响应的服务核心框架。”

我还发现了以下三个生成器;然而,第一个是关于一些丢失文件的错误,第二个代码在我尝试构建时生成和无尽的 ARC 错误流(并且重构不起作用),第三个是付费墙。

  1. http://easywsdl.com/
  2. https://code.google.com/p/wsdl2objc/
  3. http://sudzc.com/

谁能引导我朝着正确的方向前进?

【问题讨论】:

  • 那么,@kmiklas,您找到解决方案了吗?

标签: ios objective-c xcode soap wsdl


【解决方案1】:

几个月前我遇到了同样的情况,我目前正在使用需要连接到 SOAP 服务的 iPad 应用程序。我已经有了这些课程,但它们是针对我的项目的,我无权分享它。不过,我正在制作一个更通用的 Objective-C 类(无论如何都是所有 SOAP 服务器的最终解决方案),以便在 Github 上与全世界分享。

首先您必须设置 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>

我告诉你,我正在为其制作应用程序的公司已向我提供了方法和身份验证信息。我不知道这是否是你的情况,但你在这里大致了解了该怎么做。

我使用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 显然是服务器 URL。如果请求成功,那么您已经准备好解析服务器的 xml 响应。如果不是,则返回请求错误说明。

这个页面帮助我找到了解决我遇到的一些问题的方法,它与你上面引用的网站http://sudzc.com/有关:

http://blog.exadel.com/working-with-ios-and-soap/

我希望这对您有所帮助。

【讨论】:

  • Github 仓库名称是什么?
  • 它在我的本地存储库中,直到我完成它。
  • 检查一下你有什么。
  • 顺便说一句,您在“NSLog(@"Bad SOAP server!..." 错误消息中忘记了分号。
猜你喜欢
  • 2013-08-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-12-30
  • 1970-01-01
  • 1970-01-01
  • 2012-06-14
相关资源
最近更新 更多