2015-02-06 86 views
3

我被困在一個SOAP集成項目中。我需要從iPad應用程序調用一些SOAP Web服務。來自WSDL的針對Objective-C的SOAP客戶端生成器?

我有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相對簡單,只需要更多的努力,就可以將方法名稱,數據類型和參數名稱提取爲構建一個SOAP調用,然後可以使用Web Services Core框架來進行SOAP調用並解析響應。「

我也發現了以下三個發電機;然而,第一個是拋出關於一些丟失文件的錯誤,第二個的代碼在我嘗試構建時(和重構不起作用)產生了無盡的ARC錯誤流,第三個是支付障礙。

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

任何人都可以引導我在正確的方向?

+0

所以,@ kmiklas,你找到了解決辦法嗎? – epologee 2015-03-19 11:25:19

回答

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/

我希望這有助於在任何辦法。

+0

什麼是Github回購商名稱? – kmiklas 2015-02-06 20:19:05

+0

它在我的本地存儲庫中,直到完成它。 – thxou 2015-02-06 20:21:36

+0

只需檢查你有什麼。 – kmiklas 2015-02-06 20:31:44