【问题标题】:System.Web.Services.Protocols.SoapException: Server did not recognize the value of HTTP Header SOAPAction:System.Web.Services.Protocols.SoapException:服务器无法识别 HTTP 标头 SOAPAction 的值:
【发布时间】:2014-05-06 03:39:15
【问题描述】:

当我尝试调用 Web 服务上的方法时出现异常:

System.Web.Services.Protocols.SoapException: Server did not recognize the value of HTTP Header SOAPAction: http://localhost:53460/3Development/MyWebService.asmx/GetBasePath.
   at System.Web.Services.Protocols.Soap11ServerProtocolHelper.RouteRequest()
   at System.Web.Services.Protocols.SoapServerProtocol.RouteRequest(SoapServerMessage message)
   at System.Web.Services.Protocols.SoapServerProtocol.Initialize()
   at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)

Web 服务的命名空间:

[WebService(Namespace = "http://internaltest.temp.us/MyWebService.asmx")]

我做了一些研究,发现这个异常流动是因为项目中引用的 web 服务的命名空间与服务器 web 服务的命名空间不同,但是我尝试删除 web 引用并在项目中再次添加它,但是结果还是一样。

我的情况类似于下面的文章:

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

来自文章:

所以基本上网络服务是从http://foo.com/servicenamehttp://bar.com/servicename 但 Web 服务的“命名空间” 保持为http://foo.com/servicename,因为没有人更改它。

问题是:

如何更改网络引用的命名空间?

【问题讨论】:

  • 您能否提供原始请求的捕获(使用 Fiddler 之类的工具)?此外,一旦您收到请求,请尝试更改命名空间并使用 SoapUI 向您的服务发送请求以确保其正常工作。
  • 刚刚更换了整个webreference的命名空间,问题解决了

标签: c# asp.net web-services exception soap


【解决方案1】:

除了删除和添加网络引用之外,您还可以尝试使用 wsdl.exe 重新生成代理,如建议的 here 那样,再次使用命名空间。希望对你有帮助

【讨论】:

    【解决方案2】:

    调用网络服务时我也遇到了同样的异常。在我的客户端代码中,我使用了错误的命名空间来引用 WebService。因此,每当提到 WebService 时,我都会使用完全限定名称,例如:Namespace.WebService,它为我解决了这个问题。

    【讨论】:

      【解决方案3】:

      分享我的经验,因为这可能会对那里的人有所帮助。

      案例说明:

      实际方法:

      [WebMethod]
      public string Bar(){
      }
      

      您将其重命名为Foo

      [WebMethod]
      public string Foo(){
      }
      

      错误调用的方法:

      objectName.Bar();
      

      正确调用:

      objectName.Foo();
      

      实际 Web 方法和被调用方法之间的名称冲突 (由于 Web 方法的重命名)可能会导致问题。

      【讨论】:

        【解决方案4】:

        另一种获取错误的无耻方法是,如果您正在动态更改端点 url,并且您输入的是 asmx 地址而不是 wcf 地址,反之亦然。

        【讨论】:

          【解决方案5】:

          当 WS 的 SOAPAction 属性的值未设置 (null) 或在发送的请求中不正确时,可能会发生这种情况。我正在使用 apache 库连接到我当前项目中的服务,您可以在下面找到我的解决方案/解决方法。

          import org.apache.axis.client.Call;
          import org.apache.axis.client.Service;
          
          call = (Call) service.createCall();
          call = setUseSOAPAction(true);
          

          由于我的 apache 案例没有 setSoapAction 方法,我使用了他们的 setProperty 方法并手动为该属性分配了 SOAPAction 名称。

          call.setProperty("SOAPAction", "expected SOAPAction value");
          call.setSOAPActionURI("expected SOAPAction value");
          

          如果不同时使用这两种方法,我无法调用服务。

          我希望这会有所帮助。

          【讨论】:

            猜你喜欢
            • 2018-11-16
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2014-12-02
            • 2021-10-17
            • 2011-12-19
            • 1970-01-01
            相关资源
            最近更新 更多