ios - 来自 WSDL 的 Objective-C 的 SOAP 客户端生成器?

标签 ios objective-c xcode soap wsdl

我被困在一个 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甚至说(强调):

"Currently, OS X provides no high-level support for 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."

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

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

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

最佳答案

几个月前我遇到了同样的情况,目前我正在开发一个需要连接到 SOAP 服务的 iPad 应用程序。我已经有了这些类(class),但它们是我的项目特有的,我无权共享它。但是,我正在制作一个更通用的 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/

我希望这对您有所帮助。

关于ios - 来自 WSDL 的 Objective-C 的 SOAP 客户端生成器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28373194/

相关文章:

ios - 推送新 View Controller 时如何让语音读出标题?

iphone - 比较两个 Xcode build设置

objective-c - Objective-C - 自定义 @synthesize?

xcode - UIColor Swift 给出不同的颜色

ios - 在我的 UITableView 中设置特定单元格的高度

ios - iTunes 连接在应用程序购买问题

ios - 动画约束正在打破其他约束

ios - 如何通过地址显示 UIImageView Quick Look?

c++ - 为什么对函数 "sample_mean"的调用不明确?

ios - 使用 NSFetchedResultsController 后 TableView 保持为空