简体   繁体   English

通过编程方式定义绑定而不是App.Config时出现“ SoapException:服务器无法识别HTTP标头SOAPAction的值”

[英]“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. 我有一个asmx Web服务。 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.: 因此,我试图使用ChannelFactory服务读取应用程序的配置。

 BasicHttpBinding myBinding = new BasicHttpBinding();

And set all the attributes from my app.config. 并从我的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. 您可以做的一件事是在服务界面中的OperationContract属性中更改Action属性。

[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. 但这对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 System.Web.Services.Protocols.SoapException:服务器无法识别HTTP标头SOAPAction的值: - System.Web.Services.Protocols.SoapException: Server did not recognize the value of HTTP Header SOAPAction: 服务器无法识别 HTTP Header SOAPAction 的值 - Server did not recognize the value of HTTP Header SOAPAction 服务器无法识别HTTP标头SOAPAction的值:“” - Server did not recognize the value of HTTP Header SOAPAction: “” Message =服务器无法识别HTTP标头SOAPAction的值:错误 - Message=Server did not recognize the value of HTTP Header SOAPAction: error 服务器无法识别HTTP标头SOAPAction启动的值 - Server did not recognize the value of HTTP Header SOAPAction initiate 以编程方式更改defaultproxy而不是使用app.config - Programmatically changing defaultproxy instead of using app.config 以编程方式设置默认代理而不是使用app.config - set default proxy programmatically instead of using app.config 从app.config移入构造函数时,绑定失败 - Binding fails when moved in to constructor from app.config 如何从 C# 中的服务器位置获取 app.config 值 - How to app.config value from server location in c# 如何从使用WCF绑定的app.config转到如何以正确的方式将其转换为以编程方式进行绑定 - how to go from using app.config of WCF binding and convert it to bind programmatically in correct manner
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM