passing parameter to java webservice from sudzC ios always null

1.1k Views Asked by At

Soap Request tested using glassfish web service tester

<?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 Response

<?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>

now i try to call this hello method on my ios using sudz to pass 'name' parameter to the webservice. so this is code inside 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>"];

here is netbeans log when accessed by ios

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

log when accessed by android

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

but it always return null parameter, and in android using ksoap and it works perfectly. with those envelope above i could call the method (hello) but it passing null parameter. please help T_T

1

There are 1 best solutions below

1
On BEST ANSWER

Since nobody has answered this yet and I had the same problem which was not solved by other posts around the web...

I have ARC enabled, no problems there. I did generate the ARCless version and that worked as well though I'm sticking with ARC. I had to change the code that generated the parameters for the request in Soap.m. I added the xmlns="" in the return line

// 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];
}

I also had to make this change:

Referenced here: http://code.google.com/p/sudzc/issues/detail?id=40 Changed from:

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

To this

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

This is the SOAP request that finally ended up working for me.

<?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>