[英]System.Web.Services.Protocols.SoapException: Server did not recognize the value of HTTP Header SOAPAction:
An exception flows when I was trying to call a method on web service: 当我尝试在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)
The web service's namespace: Web服务的命名空间:
[WebService(Namespace = "http://internaltest.temp.us/MyWebService.asmx")]
I did some research and found out that this exception flows because the web service's namespace referenced in the project was different from the server web service's namespace, but I've tried removing web reference and add it again in the project, but the result was still the same. 我做了一些研究,发现这个异常流程是因为项目中引用的Web服务的命名空间与服务器Web服务的命名空间不同,但我尝试删除Web引用并在项目中再次添加它,但结果仍然是相同。
My situation was similar to the below article: 我的情况类似于下面的文章:
http://bluebones.net/2003/07/server-did-not-recognize-http-header-soapaction/ http://bluebones.net/2003/07/server-did-not-recognize-http-header-soapaction/
From Article: 来自文章:
So basically the web service was moved from http://foo.com/servicename to http://bar.com/servicename but the “namespace” of the web service stayed as http://foo.com/servicename because no one changed it.
所以基本上Web服务从http://foo.com/servicename移到了http://bar.com/servicename,但Web服务的“命名空间”保持为http://foo.com/servicename,因为没有人改变了
The problem is: 问题是:
How to change the namespace of the web reference? 如何更改Web引用的命名空间?
I also got same exception when calling a webservice. 调用webservice时我也遇到了同样的异常。 In my client code, I was using wrong the Namespace to refer to the WebService.
在我的客户端代码中,我使用错误的命名空间来引用WebService。 So, whenever I was refered to the WebService, I used fully qualified names like: Namespace.WebService, which solved the issue for me.
因此,每当我被引用到WebService时,我都使用了完全限定的名称,例如:Namespace.WebService,它为我解决了这个问题。
Sharing my experience, because this may help someone out there. 分享我的经验,因为这可以帮助那里的人。
Example to explain the case: 举例解释案例:
Actual method: 实际方法:
[WebMethod]
public string Bar(){
}
You renamed it to Foo
您将其重命名为
Foo
[WebMethod]
public string Foo(){
}
Wrongly called method: 错误地称为方法:
objectName.Bar();
Correct call: 正确的电话:
objectName.Foo();
A name conflict (because of renaming of web method) between actual web method and the called method can cause the issue.
实际Web方法和被调用方法之间的名称冲突 (因为重命名Web方法)可能会导致问题。
获得错误的另一种无耻方式是,如果您正在动态更改端点URL,并且输入了asmx地址而不是wcf地址,反之亦然。
This can happen when the value of the SOAPAction
property of the WS is not set ( null
) or not correct in the request sent. 当WS的
SOAPAction
属性的值未设置( null
)或在发送的请求中不正确时,可能会发生这种情况。 I am using the apache library to connect to the services in my current project, and below you can find my solution/workaround. 我使用apache库连接到当前项目中的服务,下面你可以找到我的解决方案/解决方法。
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
call = (Call) service.createCall();
call = setUseSOAPAction(true);
Since there is not a setSoapAction
method for my apache case, I used their setProperty
method and assigned the SOAPAction
name to that property manually. 由于我的apache情况没有
setSoapAction
方法,我使用了他们的setProperty
方法并手动将SOAPAction
名称分配给该属性。
call.setProperty("SOAPAction", "expected SOAPAction value");
call.setSOAPActionURI("expected SOAPAction value");
I could not invoke the service without using those both methods at the same time. 我不能在不同时使用这两种方法的情况下调用服务。
I hope this will help. 我希望这将有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.