使用glassfish网络服务测试人员测试肥皂请求
<?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>
肥皂反应
<?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>
现在我尝试在我的ios上调用这个hello方法,使用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>"];
这是ios访问时的netbeans日志
INFO: Received WS-I BP non-conformant Unquoted SoapAction HTTP header: http://WS/hello
INFO: berhasil null
访问android时的日志
INFO: Received WS-I BP non-conformant Unquoted SoapAction HTTP header: http://WS/hello
INFO: berhasil Cornel
但它总是返回null参数,在android中使用ksoap并且它完美地工作。 使用上面的那些信封我可以调用方法(hello),但它传递null参数。请帮助T_T
答案 0 :(得分:2)
由于没有人回答这个问题,我遇到了同样的问题,这个问题并没有被网上的其他帖子解决......
我启用了ARC,没有问题。我确实生成了ARCless版本,虽然我坚持使用ARC,但它仍然有效。我不得不在Soap.m中更改为请求生成参数的代码。我添加了xmlns =&#34;&#34;在返回行
// 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>