【发布时间】:2019-10-28 07:15:13
【问题描述】:
我需要通过 HTTP 调用外部 SOAP 网络服务。
我有 WSDL 文件并通过“添加服务引用”将其添加到 Visual Studio 中。 Visual Studio 然后添加了一些文件,在参考文件中我可以找到这个:
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(ConfigurationName="Service.IService")]
public interface IService {
[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IService/Function", ReplyAction="http://tempuri.org/IService/FunctionResponse")]
namespace.Service.ExecuteFunctionResponse ExecuteFunction(namespace.Service.FunctionRequest request);
}
另外还有此调用的异步版本以及用于发送接收等的对象。
为了调用服务,我添加了以下代码:
BasicHttpBinding binding = new BasicHttpBinding();
EndpointAddress endpointAddress = new EndpointAddress("the address");
serviceChannel = new ServiceClient(binding, endpointAddress).ChannelFactory.CreateChannel();
Response response = serviceChannel.ExecuteFunction(new Request(...));
这导致我得到一个异常,错误 405 方法不允许。
所以看来我必须使用 HTTP GET 请求而不是默认的 POST 请求。但是我找不到这种工作方式可以改变的地方。
那么,我在哪里可以设置这个调用 Web 服务的 HTTP 方法?
【问题讨论】:
-
SOAP 已经非常停产了。您可能应该考虑将其升级到 web api 或 WCF
-
这是第三方服务,所以恐怕我无能为力。
-
可能会解释你缺乏回应。我已经有 8 年没有使用 SOAP 了,我以前很了解它,但是……嗯,那是 8 年前的事了 :)
标签: c# visual-studio web-services soap http-get