Objective-C SOAP客户端-请求有问题吗? [英] Objective-C SOAP Client --Request Problem?
问题描述
我已经用WSDL2OBJC生成了代码. 我在Objective C客户端中的请求存在很大问题:
I have generated code with WSDL2OBJC. I have big problem with request in my Objective C client:
CatalogoPortBinding *binding = [[CatalogoSvc CatalogoPortBinding] initWithAddress:@"http://localhost:8080/WSServer/Catalogo_V1"];
binding.logXMLInOut = YES; // to get logging to the console.
CatalogoSvc_hello *request = [[CatalogoSvc_hello alloc] init];
NSString *t = @"David";
request.name = t;
NSLog(@"request: %@",request.name);
CatalogoPortBindingResponse *response = [binding helloUsingParameters:request];
//NSLog(@"%@",resp.bodyParts);
for (id mine in response.bodyParts)
{
NSLog(@"name: %@",[mine return_]);
if ([mine isKindOfClass:[CatalogoSvc_helloResponse class]])
{
if (sec == YES) {
//NSLog(@"name: %@",[mine return_]);
NSString *texto = (NSString*)[mine return_];
[lab setText:(NSString*)texto];
}
}
}
我的控制台显示:
2011-08-31 12:29:05.086 Catalogo-V1[3596:207] request: David
2011-08-31 12:29:05.088 Catalogo-V1[3596:207] OutputHeaders:
{
"Content-Length" = 434;
"Content-Type" = "text/xml; charset=utf-8";
Host = localhost;
Soapaction = "";
"User-Agent" = wsdl2objc;
}
2011-08-31 12:29:05.088 Catalogo-V1[3596:207] OutputBody:
<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:CatalogoSvc="http://org/" xsl:version="1.0">
<soap:Body>
<CatalogoSvc:hello>
<CatalogoSvc:name>David</CatalogoSvc:name>
</CatalogoSvc:hello>
</soap:Body>
</soap:Envelope>
2011-08-31 12:29:05.093 Catalogo-V1[3596:207] ResponseStatus: 200
2011-08-31 12:29:05.094 Catalogo-V1[3596:207] ResponseHeaders:
{
"Content-Type" = "text/xml;charset=utf-8";
Date = "Wed, 31 Aug 2011 10:29:05 GMT";
Server = "GlassFish Server Open Source Edition 3.1.1";
"Transfer-Encoding" = Identity;
"X-Powered-By" = "Servlet/3.0 JSP/2.2 (GlassFish Server Open Source Edition 3.1.1 Java/Apple Inc./1.6)";
}
2011-08-31 12:29:05.094 Catalogo-V1[3596:207] ResponseBody:
<?xml version='1.0' encoding='UTF-8'?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><ns2:helloResponse xmlns:ns2="http://org/"><return>Hello null !</return></ns2:helloResponse></S:Body></S:Envelope>
2011-08-31 12:29:05.095 Catalogo-V1[3596:207] name: Hello null !
我需要显示以下消息:大卫你好!"然后我收到:你好,空!".
I need to show this message: "Hello David !" and i receive: "Hello null!".
推荐答案
基于将该请求与您在发布的问题中的请求进行了比较关于手动解决方案,看来您这里遇到了名称空间问题.此处生成的SOAP请求(通过标识符CatalogoSvc)将 http://org/命名空间应用于名称"元素:
Based on comparing this request to what you have in your question posted about a manual solution, it looks like you've got namespace issues happening here. The SOAP request generated here applies the http://org/ namespace (via the identifier CatalogoSvc) to the "name" element:
<CatalogoSvc:hello>
<CatalogoSvc:name>David</CatalogoSvc:name>
</CatalogoSvc:hello>
在手动操作的情况下,将 http://org/命名空间应用于周围的"hello"元素而不是"name"元素:
In the manual scenario where you have gotten this to work, the http://org/ namespace is applied to the surrounding "hello" element but not the "name" element:
<ns2:hello xmlns:ns2="http://org/>
<name>david</name>
</ns2:hello>
基于这种观察,我可以推断出您的服务不希望将名称空间应用于名称元素,因此在与名称空间一起发送时不会找到该参数.
Based on this observation, I would deduce that your service is not expecting a namespace to be applied to the name element, so it is not finding that parameter when it is sent with a namespace.
要解决此问题,您将需要:
To fix this problem you will need to either:
- 弄清楚如何告诉SOAP客户端存根生成器不要将名称空间应用于您的参数,或者
- 更新您的服务以使其使用命名空间的名称"元素.
由于客户端代码大概是从服务的WSDL生成的,因此我怀疑Objective-C代码做对了,而您的服务代码却做错了,但这只是怀疑.无论哪种方式,您都需要找到一种使客户端和服务器端同意"的方法
Since the client side code is presumably generated from the service's WSDL, I suspect that the Objective-C code is doing it right and your service code has it wrong, but that's just a suspicion. Either way, you need to find a way to make client and server side "agree"
这篇关于Objective-C SOAP客户端-请求有问题吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!