简体   繁体   中英

“SoapException: Server did not recognize the value of HTTP Header SOAPAction” when programmatically defining Binding instead of App.Config

I have an asmx web service. On the client side, I don't want to use app config. So I am trying to read the configuration of my application using a ChannelFactory service.:

 BasicHttpBinding myBinding = new BasicHttpBinding();

And set all the attributes from my app.config. Then I have defined my endpoint and channel factory:

EndpointAddress myendpoint = new EndpointAddress("http://localhost:<portNumber>/<serviceName>.asmx");
ChannelFactory<IServiceInterface> myCh = new ChannelFactory<IServiceInterface>(myBinding, myendpoint);
IServiceInterface service = myCh.CreateChannel();

This is the error I get when calling a method from my channel:

System.Web.Services.Protocols.SoapException: Server did not recognize the value of HTTP Header     SOAPAction: http://localhost/<serviceName.asmx/IServiceInterface/<MethodName>.
at System.Web.Services.Protocols.Soap11ServerProtocolHelper.RouteRequest()
at System.Web.Services.Protocols.SoapServerProtocol.RouteRequest

One of the things you can do is to change Action property in OperationContract attribute in your service's interface.

[ServiceContract]
interface IService
{
    [OperationContract(Action = "http://tempuri.org/GetString")]
    string GetString();
}

I am not sure this is the best solution, searching for another one and will prompt if find anything. But this one works for me.

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