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

当我尝试在Web服务上调用方法时,会发生exception:

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")] 

我做了一些研究,发现这个exception流程是因为项目中引用的Web服务命名空间与服务器Web服务的命名空间不同,但我尝试删除Web引用并在项目中再次添加它,但结果仍然是相同。

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

Server did not recognize the value of HTTP Header SOAPAction

来自文章:

所以基本上Web服务从http://foo.com/servicename转移到http://bar.com/servicename但是Web服务的“命名空间”仍然是http://foo.com/servicename,因为没有人改变了

问题是:

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

除了删除和添加web-reference之外,您还可以尝试使用wsdl.exe重新生成代理,如此处所示,再次使用命名空间。 希望能帮助到你

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

分享我的经验,因为这可以帮助那里的人。

举例解释案例:

实际方法:

 [WebMethod] public string Bar(){ } 

您将其重命名为Foo

 [WebMethod] public string Foo(){ } 

错误地称为方法:

 objectName.Bar(); 

正确的电话:

 objectName.Foo(); 

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

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

当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"); 

我不能在不同时使用这两种方法的情况下调用服务。

我希望这将有所帮助。