2012-07-25 68 views
0

SOAP請求中使用GlassFish Web服務測試程序測試傳遞參數從sudzC Java的web服務的iOS總是空

<?xml version="1.0" encoding="UTF-8"?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> 
<S:Header/> 
<S:Body> 
    <ns2:hello xmlns:ns2="http://WS/"> 
     <name>asd</name> 
    </ns2:hello> 
</S:Body> 

SOAP響應

<?xml version="1.0" encoding="UTF-8"?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> 
<S:Body> 
    <ns2:helloResponse xmlns:ns2="http://WS/"> 
     <return>Hello asd !</return> 
    </ns2:helloResponse> 
</S:Body> 

現在我打電話這個hello方法在我的ios上使用sudz將'name'參數傳遞給webservice。 所以這裏面createEnvelope代碼:

[s appendString: @"<?xml version=\"1.0\" encoding=\"utf-8\"?>"]; 
[s appendString:@"<S:Envelope xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\">"]; 
[s appendString:@"<S:Header/>"]; 
[s appendString:@"<S:Body>"]; 
[s appendString:@"<ns2:hello "]; 
[s appendString:@"xmlns:ns2=\"http://WS/"]; 
[s appendString:@"\"/>"]; 
[s appendString:@"<name>alvin</name>"]; 
[s appendString:@"</ns2:hello> "]; 
[s appendString:@"</S:Body>"]; 
[s appendString:@"</S:Envelope>"]; 

這裏是NetBeans的日誌時IOS時由Android

INFO: Received WS-I BP non-conformant Unquoted SoapAction HTTP header: http://WS/hello 
INFO: berhasil Cornel 

訪問,但它總是返回null參數訪問

INFO: Received WS-I BP non-conformant Unquoted SoapAction HTTP header: http://WS/hello 
INFO: berhasil null 

日誌和在android使用kso​​ap和它完美的作品。 與上面的那些信封我可以調用方法(你好),但它傳遞null參數。請幫助T_T

回答

2

由於還沒有人回答了這個,我有哪些沒有被網絡上的其他職位解決同樣的問題...

我啓用了ARC,沒有問題存在。我確實生成了ARCless版本,雖然我堅持使用ARC,但它的工作方式也一樣。我必須更改生成Soap.m中的請求參數的代碼。我加入的xmlns = 「」 回油管路

// Serializes an object to a string, XML representation with a specific node name. 
+ (NSString*) serialize: (id) object withName: (NSString*) nodeName { 
    if([object respondsToSelector:@selector(serialize:)]) { 
     return [object serialize: nodeName]; 
    } 
    return [NSString stringWithFormat:@"<%@ xmlns=\"\">%@</%@>", nodeName, [Soap serialize: object], nodeName]; 
} 

我也不得不做出這樣的改變:

此處引用:http://code.google.com/p/sudzc/issues/detail?id=40 變更情況:從

if([child respondsToSelector:@selector(name)] && [[child name] isEqual: name]) { 

對此

if([child respondsToSelector:@selector(name)] && [[child name] hasSuffix:: name]) { 

這是最終結束爲我工作的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/" 
xmlns="http://webservice.alerts.xxxconsulting.com/"> 
<soap:Body> 
<echo> 
<arg0 xmlns="">echo msg</arg0> 
</echo> 
</soap:Body> 
</soap:Envelope> 
+0

謝謝你的隊友的答案,其實我沒有繼續我的研究在這裏,所以我轉移到JSON代替。儘管json比這個肥皂更快。 :) – xeravim 2012-12-04 13:28:12