从WSDL生成Objective-C的SOAP客户端生成器?

3
我被困在一个SOAP集成项目中。我需要从iPad应用程序调用一些SOAP Web服务。
我有WSDL,我需要生成Objective-C类来调用服务调用。
Mac开发人员库有一个"示例:使用HTTP身份验证调用SOAP操作",但它链接到的示例代码已经损坏了(SOAP_AuthExample.dmg, 404)。 Web Services Core Programming Guide甚至说(重点加粗):
"目前,OS X没有提供从WSDL文件中提取SOAP函数的高级支持。但是,您可以使用NSXMLParser从URL将WSDL文件读入内存。然后,可以相对简单地搜索特定方法名称或查找与服务相关联的URL。通过更多的努力,您可以提取方法名称、数据类型和参数名称以构建SOAP调用。然后,您可以使用Web Services Core框架进行SOAP调用并解析响应。"
"我还发现了以下三个生成器; 然而,第一个会抛出一些缺失文件的错误,第二个代码在尝试构建时会生成无尽的ARC错误(重构也不起作用),第三个则需要付费。"
  1. http://easywsdl.com/
  2. https://code.google.com/p/wsdl2objc/
  3. http://sudzc.com/

有人能指导我朝正确的方向吗?


那么,@kmiklas,你找到解决方案了吗? - epologee
1个回答

2
我是您几个月前的同样处境,目前正在开发一款需要连接到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仓库的名称是什么? - kmiklas
在我完成它之前,它在我的本地代码库中。 - thxou
只需检查您所拥有的内容。 - kmiklas
1
顺便提一下,在你的“NSLog(@”Bad SOAP server!…”错误消息中,你忘了一个分号。 - kmiklas

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接