ios - 使用 SOAP 网络服务时出现 "No Action header was found"错误消息

标签 ios objective-c soap wsdl nsurlrequest

在 iOS 应用程序中使用 SOAP 网络服务时出现以下错误

"No Action header was found with namespace 'http://www.w3.org/2005/08/addressing' for the given message."

相同的网络服务在 SOAP UI 工具中运行良好。

请求格式如下

NSString *data = @"<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:tem=\"http://tempuri.org/\">
<soap:Header></soap:Header>
<soap:Body><tem:GetEvaluators></tem:GetEvaluators></soap:Body>
</soap:Envelope>";

NSString *url = @"webservice url";
NSData *postData = [data dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:url]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setHTTPBody:postData];
[request setTimeoutInterval:20.0];
[request setValue:@"application/soap+xml;charset=UTF-8" forHTTPHeaderField:@"Content-Type"];
[request setValue:@"http://tempuri.org/IATCService/GetEvaluators" forHTTPHeaderField:@"SOAPAction"];
 NSData *urlData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];

从网络服务收到完整的错误响应

<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing">
<s:Header>
    <a:Action s:mustUnderstand="1">http://www.w3.org/2005/08/addressing/fault</a:Action>
</s:Header>
<s:Body>
    <s:Fault>
        <s:Code>
            <s:Value>s:Sender</s:Value>
            <s:Subcode>
                <s:Value>a:MessageAddressingHeaderRequired</s:Value>
            </s:Subcode>
        </s:Code>
        <s:Reason>
            <s:Text xml:lang="en-US">No Action header was found with namespace 'http://www.w3.org/2005/08/addressing' for the given message.</s:Text>
        </s:Reason>
        <s:Detail>
            <a:ProblemHeaderQName>a:Action</a:ProblemHeaderQName>
        </s:Detail>
    </s:Fault>
</s:Body>

非常感谢任何帮助。

最佳答案

我们在基于 ASP.NET 的服务器上遇到了同样的问题(使用 python/suds 时出现错误消息,相同的查询在 SoapUi 中有效);经过大量挖掘,我们发现我们需要添加一个包含操作的 SOAP header (作为 XML 元素);在 Content-Type 或 SOAPAction header 中包含操作是不够的(但也无妨)。这是一个成功查询的示例(来自 SoapUi):

<SOAP-ENV:Envelope xmlns:ns0="..." xmlns:ns1="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope">
   <SOAP-ENV:Header xmlns:wsa="http://www.w3.org/2005/08/addressing"><wsa:Action>http://www.foo.com/.../SomeJob/getParameters</wsa:Action></SOAP-ENV:Header>
   <ns1:Body>
      <ns0:getParameters>...</ns0:getParameters>
   </ns1:Body>
</SOAP-ENV:Envelope>

对于 Python 和 SUDS,我们是这样做的:

from suds.sax.element import Element
wsans = ('wsa', "http://www.w3.org/2005/08/addressing")
client.set_options(soapheaders = Element('Action', ns=wsans).setText(action))

可以从方法中查询 Action ,即如果你想调用方法 client.service.foo,使用

action = client.service.foo.method.soap.action

我们通过查看 SoapUi HTTP 日志发现了这一点。 (我们也尝试过 Wireshark,但这行不通,因为我们正在尝试使用不属于我们的 https 服务器。)

关于ios - 使用 SOAP 网络服务时出现 "No Action header was found"错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16445945/

相关文章:

php - SOAP 服务器未获取所有参数

iphone - 如何使用 UISlider 以及如何在特定值上设置 slider ?

ios - 如何快速切换 View Controller ?

iphone - 核心数据 'This NSPersistentStoreCoordinator has no persistent stores. It cannot perform a save operation.'

iphone - 在 Settings.app 中隐藏应用程序特定的设置

ios - 如何将 NSDate 的秒数设置为零

ios - 获取 iOS 中 uiimage View 特定部分的点击处理操作

ios - 调整 tabbarcontroller 中所有 viewcontroller 框架的大小

java - 从 java 调用 Soap Webservice(用 C# 编写)

java - 将 XML 声明添加到 soap 消息