gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-10-30 20:16:29 26 4
gpt4 key购买 nike

我被困在一个 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com