SoapException:服务器没有识别HTTP报头的值SOAPAction"当以编程方式定义Binding

本文关键字:quot 编程 Binding 定义 方式 SOAPAction 服务器 识别 报头 HTTP SoapException | 更新日期: 2023-09-27 18:08:19

我有一个asmx web服务。在客户端,我不想使用app配置。所以我试图使用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

SoapException:服务器没有识别HTTP报头的值SOAPAction"当以编程方式定义Binding

您可以做的一件事是更改服务接口中的OperationContract属性中的Action属性。

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

我不确定这是最好的解决方案,寻找另一个,如果找到任何提示。