0

我有一个带有 WSDL 之类的普通 3rd 方 SOAP 服务。问题是 - 它只接受 GET 请求。如何在 c# 中访问它?

当我将该服务添加到 VS viaAdd Service Reference并尝试照常使用它时:

var service = new BaseSvcClient(
                 new BasicHttpContextBinding(), 
                 new EndpointAddress("http://some.internal.ip/WebServices/Base.svc"));
var ver = service.Version();

我看到(通过提琴手)它实际上发送 POST 请求,并且 Web 服务以Endpoint not found错误消息响应。如果我只是http://some.internal.ip/WebServices/Base.svc/Version在浏览器中点击,则会返回正确的 xml。

我可以使用 WebClient,但是我必须手动构造所有的 GET 请求,这看起来不太好。还有其他解决方案吗?

4

2 回答 2

1

我找到了一个对我有很大帮助的答案。基本上,如果我为客户端采用自动生成的界面,则使用[WebGet]并使用装饰方法

var cf = new WebChannelFactory<IBaseSvc2>(new Uri("..."));
var service = cf.CreateChannel();
var result = service.Version();

这一切都很好。这不是一个完美的解决方案,因为不会自动获取更改,所以可能还有其他解决方案吗?

PS Web 服务的接口现在如下所示:

    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
    [System.ServiceModel.ServiceContractAttribute(ConfigurationName = "BaseService.IBaseSvc")]
    public interface IBaseSvc2
    {
        [System.ServiceModel.OperationContractAttribute(Action = "http://tempuri.org/IBaseSvc/Version", ReplyAction = "http://tempuri.org/IBaseSvc/VersionResponse")]
        [WebGet]
        VersionInformation Version();
    }
于 2012-10-03T10:10:42.097 回答
0

您可以通过在配置文件中添加协议来实现

<webServices>
      <protocols>
        <add name="HttpGet"/>
        <add name="HttpPost"/>
      </protocols>
</webServices>
于 2012-10-03T08:52:43.523 回答