繁体   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

我有一个asmx Web服务。 在客户端,我不想使用应用程序配置。 因此,我试图使用ChannelFactory服务读取应用程序的配置。

 BasicHttpBinding myBinding = new BasicHttpBinding();

并从我的app.config中设置所有属性。 然后,我定义了端点和通道工厂:

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

这是从通道调用方法时遇到的错误:

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

您可以做的一件事是在服务界面中的OperationContract属性中更改Action属性。

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

我不确定这是否是最好的解决方案,正在寻找另一种解决方案,并会提示是否找到任何东西。 但这对我有用。

暂无
暂无

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

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