简体   繁体   中英

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:

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:

[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.

My situation was similar to the below article:

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.

The problem is:

How to change the namespace of the web reference?

In addition to removing and adding web-reference, you could try regenerating proxies using wsdl.exe as suggested here , with the namespace again. Hope it helps

I also got same exception when calling a webservice. In my client code, I was using wrong the Namespace to refer to the WebService. So, whenever I was refered to the WebService, I used fully qualified names like: Namespace.WebService, which solved the issue for me.

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

[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.

获得错误的另一种无耻方式是,如果您正在动态更改端点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. I am using the apache library to connect to the services in my current project, and below you can find my solution/workaround.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM