Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用GET而不是POST使用SOAP Web服务_C#_Visual Studio_Web Services_Soap_Http Get - Fatal编程技术网

C# 使用GET而不是POST使用SOAP Web服务

C# 使用GET而不是POST使用SOAP Web服务,c#,visual-studio,web-services,soap,http-get,C#,Visual Studio,Web Services,Soap,Http Get,我需要通过HTTP调用外部SOAP Web服务。 我有WSDL文件,并通过“添加服务引用”将其添加到VisualStudio中。Visual studio随后添加了许多文件,在参考文件中我可以找到: [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")] [System.ServiceModel.ServiceContractAttribute(ConfigurationName="Se

我需要通过HTTP调用外部SOAP Web服务。
我有WSDL文件,并通过“添加服务引用”将其添加到VisualStudio中。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服务使用HTTP POST,因为它们交换XML消息(往往比较复杂),并且不能在查询字符串中传输

您确定必须使用HTTP GET吗?您接收到的“405方法不允许”错误可能是由某些错误配置引起的。 我将再次检查SOAP端点URL是否设置正确,并检查是否不需要额外的安全要求

编辑 过去,有一种做法是创建ASP.NETWeb服务,它也可以接受GET。但他们不希望看到XML消息。相反,您必须在querystring中传递所有参数。例如:
https://foo.bar/service.asmx/Func?param1=X¶m2=Y
(其中param1和param2是预期参数)

通过这种方式,可以在不需要WSDL和使用GET方法的情况下调用web服务。例如,您可以使用HttpClient来实现它。 这种方法的缺点是必须处理普通数据而不是对象


我希望它能有所帮助。

肥皂已经停产了很多。您可能应该考虑将其升级到web api或WCFIt的第三方服务,因此我恐怕对此无能为力。不过,这可能是您缺乏响应的原因。我已经有8年没有使用SOAP了,我以前对它很了解,但是…那是8年前:)我以前查过它,根据这里的其他问题,它很少见,通常不会使用,但可能会使用,并且得到w3c标准的支持。来源:要发送的数据相当有限,他们给出的调用服务的示例是单个URL。但是,在wsdl中查看时,它是一个SOAP服务。所以我对整件事感到困惑。我想我会采纳你的建议,联系服务的所有者,听听配置中是否有错误。你在编辑中使用的方法成功了。奇怪的是,我竟然忽略了整个SOAP部分,但如果它起作用的话。。。如果赏金允许我在几个小时内拿到的话,我会奖励的。@kyudosai你说得对。当以这种方式使用它时,它实际上不是SOAP(没有XML)。这更像是休息。我只在ASP.NET中遇到过这种情况。我很高兴我帮助了你:)