C# 服务器无法识别 HTTP Header SOAPAction 的值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/352174/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 00:12:22  来源:igfitidea点击:

Server did not recognize the value of HTTP Header SOAPAction

c#javascriptweb-services

提问by user42070

   [SoapRpcMethod(Action = "http://cyberindigo/TempWebService/InsertXML",
    RequestNamespace = "http://cyberindigo/TempWebService/Request",
    RequestElementName = "InsertXMLRequest",
    ResponseNamespace = "http://cyberindigo/TempWebService/Response",
    ResponseElementName = "InsertXMLResponse",
    Use = System.Web.Services.Description.SoapBindingUse.Literal)]

    [WebMethod]
    public string InsertXML(string Jobs)
    {
        return "Hi";
    }

The Problem when I am accessing it using XMLHttpRequest it gives following error Server did not recognize the value of HTTP Header SOAPAction: http://Cyberindigo/TempWebService/InsertXML

当我使用 XMLHttpRequest 访问它时出现以下错误服务器无法识别 HTTP 标头 SOAPAction 的值:http://Cyber​​indigo/TempWebService/InsertXML

回答by ya23

I had similar issue. To debug the problem, I've run Wiresharkand capture request generated by my code. Then I used XML Spy trialto create a SOAP request (assuming you have WSDL) and compared those two.

我有类似的问题。为了调试问题,我运行了Wireshark并捕获了我的代码生成的请求。然后我使用XML Spy 试验来创建一个 SOAP 请求(假设您有 WSDL)并比较这两个请求。

This should give you a hint what goes wrong.

这应该会给你一个提示是什么地方出了问题。

回答by ya23

The source of the next part of this post is:

这篇文章下一部分的来源是:

http://bluebones.net/2003/07/server-did-not-recognize-http-header-soapaction/

http://bluebones.net/2003/07/server-did-not-recognize-http-header-soapaction/

(since the OP didn't want to give attribution, and thanks to Peter)

(因为 OP 不想给出归属,感谢彼得)

Please note that bakert is the original author of the text, not the OP.

请注意,bakert 是文本的原作者,而不是 OP。



Seeing as nowhere on the internet can I find an explanation of this error I thought I'd share the fruits of my long search for this bug.

在互联网上找不到任何地方可以找到此错误的解释,我想我会分享我长期搜索此错误的成果。

It means (at least in my case) that you are accessing a web service with SOAP and passing a SOAPActionparameter in the HTTP request that does not match what the service is expecting.

这意味着(至少在我的情况下)您正在使用 SOAP 访问 Web 服务并SOAPAction在 HTTP 请求中传递与服务期望的参数不匹配的参数。

I got in a pickle because we moved a web service from one server to another and thus I changed the “namespace” (don't get confused between web service namespaces and .net namespaces) in the calling C# file to match the new server. But the server doesn't care about the actual web reality of http://yournamespace.com/blahit only cares that you send it what you have said you are expecting on the server. It doesn't care if there's actually anything there or not.

我陷入了困境,因为我们将 Web 服务从一台服务器移动到另一台服务器,因此我更改了调用 C# 文件中的“命名空间”(不要混淆 Web 服务命名空间和 .net 命名空间)以匹配新服务器。但是服务器并不关心http://yournamespace.com/blah它的实际网络现实,它只关心你发送它你所说的你期望在服务器上的内容。它不在乎那里是否真的有任何东西。

So basically the web service was moved from http://foo.com/servicenameto http://bar.com/servicenamebut the “namespace” of the web service stayed as http://foo.com/servicenamebecause no one changed it.

因此,基本上 Web 服务从 移到了http://foo.com/servicenamehttp://bar.com/servicename但Web 服务的“命名空间”保持不变,http://foo.com/servicename因为没有人更改它。

And that only took about 4 hours to work out!

并且只用了大约 4 个小时就完成了!

If you're having a similar problem but can't work what I'm saying here, feel free to mail me on [email protected] – I wouldn't wish my four hours on anyone!

如果您遇到了类似的问题,但无法解决我在这里所说的问题,请随时通过 [email protected] 给我发邮件——我不希望我的四个小时花在任何人身上!

回答by Ben

I agree with Sam in that the SOAP definition does not match what is expected. Here is just ONE solution it could be, I had to manually figure this error for myself:

我同意 Sam 的观点,即 SOAP 定义与预期不符。这只是一个可能的解决方案,我必须自己手动计算这个错误:

My problem was that I changed the name of the web method but did not change the "MessageName" in the metadata tag.

我的问题是我更改了 Web 方法的名称,但没有更改元数据标记中的“MessageName”。

[WebMethod(MessageName = "foo")]
public string bar()
{

}

It should be

它应该是

[WebMethod(MessageName = "foo")]
public string foo()
{

}

hope that helps someone

希望能帮助某人

回答by gaijintendo

I had to sort out capitalisation of my service reference, delete the references and re add them to fix this. I am not sure if any of these steps are superstitious, but the problem went away.

我不得不整理我的服务引用的大小写,删除引用并重新添加它们来解决这个问题。我不确定这些步骤中是否有任何一个是迷信的,但问题就解决了。

回答by Shivanand Mitkari

While calling the .asmx / wcf web service please take care of below points:

在调用 .asmx / wcf 网络服务时,请注意以下几点:

  1. The namespace is case sensitive,the SOAP request MUST be sent with the same namespace with which the WebService is declared.
  1. 命名空间区分大小写,SOAP 请求必须使用与声明 WebService 相同的命名空间发送。

e.g. For the WebService declared as below

例如对于声明如下的WebService

[WebService(Namespace = "http://MyDomain.com/TestService")] 
public class FooClass : System.Web.Services.WebService 
{
   [WebMethod]   
    public bool Foo( string name)    
     {

      ...... 
     }

 }

The SOAP request must maintain the same case for namespace while calling.Sometime we overlook the case sensitivity.

SOAP 请求在调用时必须为命名空间保持相同的大小写。有时我们会忽略大小写敏感性。

<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/">
  <soap:Body>
     <Foo xmlns="http://MyDomain.com/TestService">
     <name>string</name>      
     </Foo>
  </soap:Body> 
</soap:Envelope>
  1. The namespace need not be same as hosted url of the service.The namespace can be any string.
  1. 命名空间不必与服务的托管 url 相同。命名空间可以是任何字符串。

e.g. Above service may be hosted at http://84.23.9.65/MyTestService, but still while invoking the Web Service from client the namespace should be the same which the serice class is having i.e.http://MyDomain.com/TestService

例如,上述服务可能托管在http://84.23.9.65/MyTestService,但仍然在从客户端调用 Web 服务时,命名空间应该与服务类具有的相同,即http://MyDomain.com/TestService

回答by the_marcelo_r

I've decided to post my own answer here because I've lost a few hours on this and I think that, although the accepted answer is very good and pointed me in the right direction (yes, it got a voteup), it was not detailed enough to explain what was wrong with my application, at least in my case.

我决定在这里发布我自己的答案,因为我在这个问题上浪费了几个小时,我认为,虽然接受的答案非常好并为我指明了正确的方向(是的,它得到了投票),但它是不够详细,无法解释我的应用程序出了什么问题,至少在我的情况下是这样。

I'm running a BPEL module in OpenESB 2.2 and the Test Case of my Composite Application was failing with the following error:

我在 OpenESB 2.2 中运行 BPEL 模块,我的复合应用程序的测试用例失败并出现以下错误:

Caused by: System.Web.Services.Protocols.SoapException: Server did not recognize the value of HTTP Header SOAPAction: .

After doing some research I've noticed that the external WSDL has all the clues we need to fix this problem, e.g., I'm using the following web service to validate a credit card number through a orchestration of Web Services: http://www.webservicex.net/CreditCard.asmx?WSDL

在做了一些研究之后,我注意到外部 WSDL 具有解决这个问题所需的所有线索,例如,我使用以下 Web 服务通过 Web 服务的编排来验证信用卡号: http:// www.webservicex.net/CreditCard.asmx?WSDL

If you check the <wsdl:operationelements you will see that it clearly states the soapActionfor that operation:

如果您检查<wsdl:operation元素,您将看到它清楚地说明了soapAction该操作:

<wsdl:binding name="CCCheckerSoap" type="tns:CCCheckerSoap">
  <soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
  <wsdl:operation name="ValidateCardNumber">
    <soap:operation soapAction="http://www.webservicex.net/ValidateCardNumber" style="document"/>
    <wsdl:input>
  <soap:body use="literal"/>
</wsdl:input>
...

But, once you create the Composite Application and build the project with the BPEL that invokes this external WSDL service, for some reason (bug?), the XML of the Composite Application Service Assembly (CASA) binding is generated with an empty soapActionparameter:

但是,一旦您创建了复合应用程序并使用调用此外部 WSDL 服务的 BPEL 构建项目,出于某种原因(错误?),复合应用程序服务程序集 (CASA) 绑定的 XML 将生成一个空soapAction参数:

<binding name="casaBinding1" type="ns:CCCheckerSoap">
        <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
        <operation name="ValidateCardNumber">
            <soap:operation soapAction="" style="document"/>
            <input>
                <soap:body use="literal"/>
            </input>

Once you copy the proper soapAction (http://www.webservicex.net/ValidateCardNumber) into this parameter, the application's Test Case will correctly and return the expected Soap response.

一旦您将正确的soapAction (http://www.webservicex.net/ValidateCardNumber) 复制到此参数中,应用程序的测试用例将正确并返回预期的Soap 响应。

<soap:operation soapAction="http://www.webservicex.net/ValidateCardNumber" style="document"/>

So, it's a more specific solution that I decided to document based on the information found in this blog post: http://bluebones.net/2003/07/server-did-not-recognize-http-header-soapaction/.

所以,这是一个更具体的解决方案,我决定根据这篇博文中的信息记录下来:http: //bluebones.net/2003/07/server-did-not-recognize-http-header-soapaction/

It means (at least in my case) that you are accessing a web service with SOAP and passing a SOAPAction parameter in the HTTP request that does not match what the service is expecting.

这意味着(至少在我的情况下)您正在使用 SOAP 访问 Web 服务并在 HTTP 请求中传递与服务期望的不匹配的 SOAPAction 参数

回答by Ken

I had the same problem after changing the namespace from "tempuri" in my Web Service.

在我的 Web 服务中从“tempuri”更改命名空间后,我遇到了同样的问题。

You have to update your Service Reference in the project that is consuming the above service, so it can get the latest SOAP definitions.

您必须在使用上述服务的项目中更新您的服务引用,以便它可以获得最新的 SOAP 定义。

Or at least that worked for me. :)

或者至少这对我有用。:)

回答by TheLegendaryCopyCoder

We had renamed some of our webservice project namespaces and forgot to update the website httphandlers config section with the namespace of the renamed projects.

我们重命名了一些 webservice 项目命名空间,但忘记使用重命名项目的命名空间更新网站 httphandlers 配置部分。

回答by Zolfaghari

I had same problem, it fixed after some checking:

我有同样的问题,经过一些检查后解决了:

<< Target WebService Exists but called method's not eXXXists. >>

<< 目标 WebService 存在但被调用的方法不是 eXXXists。>>

my local service contain methods but target server(connecting server) does not contain specified called method.

我的本地服务包含方法,但目标服务器(连接服务器)不包含指定的调用方法。

Check your program scenario again...

再次检查您的程序场景...

回答by Graeme Black

I had a similar problem with the same error message:

我有同样的错误消息的类似问题:

System.Web.Services.Protocols.SoapException:Server did not recognize the value of HTTP Header SOAPAction:

System.Web.Services.Protocols.SoapException:服务器无法识别 HTTP Header 的值SOAPAction

We utilize dynamic URL's in our web service calls. We have a central configuration server that manages the location of all web service calls so that our code can run in DEV, test or live without recompiling. The URL for a specific web service call for the test environment was incorrect in our configuration server. The web service call was being sent to the wrong server and the wrong web service.

我们在 Web 服务调用中使用动态 URL。我们有一个中央配置服务器来管理所有 Web 服务调用的位置,以便我们的代码可以在 DEV 中运行、测试或实时运行而无需重新编译。在我们的配置服务器中,用于测试环境的特定 Web 服务调用的 URL 不正确。Web 服务调用被发送到错误的服务器和错误的 Web 服务。

So this error can simply be the result of the web service request not matching the web service being called.

因此,此错误可能只是 Web 服务请求与被调用的 Web 服务不匹配的结果。

It took running fiddler on the Web App server to see that the actual call was to the incorrect web service.

在 Web App 服务器上运行 fiddler 才发现实际调用的是不正确的 Web 服务。