【问题标题】:SoapHttpClientProtocol.Invoke is making a POST request and I want it to make GET, how do I do it?SoapHttpClientProtocol.Invoke 正在发出 POST 请求,我希望它发出 GET,我该怎么做?
【发布时间】:2018-08-29 15:06:31
【问题描述】:

这是我用来调用 Web 服务的类中的部分代码(该类继承自 SoapHttpClientProtocol)。每当我调用 localidades() 时,我都会从服务器收到错误 405,这是因为 localidades() 发送的是帖子而不是获取,并且服务器配置为仅允许获取。如何更改请求类型?

我尝试通过重写 GetWebRequest() 方法来更改请求类型(除了添加基本身份验证),但它只是添加了基本身份验证,而不是更改请求类型。

protected override System.Net.WebRequest GetWebRequest(Uri uri)
    {
        var request = base.GetWebRequest(uri);
        String encoded = System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes("username" + ":" + "password"));
        request.Headers.Add("Authorization", "Basic " + encoded);
        request.Method = System.Net.WebRequestMethods.Http.Get;
        return request;
    }

    /// <remarks/>
    [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/localidades", RequestNamespace="http://tempuri.org/", ResponseNamespace="http://tempuri.org/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
    public string localidades() {
        object[] results = this.Invoke("localidades", new object[0]);
        return ((string)(results[0]));
    }

【问题讨论】:

    标签: c# asp.net web-services soap-client


    【解决方案1】:

    SOAP 始终是 HTTP POST。如果服务器需要 GET,则说明它没有正确托管 SOAP 服务。

    【讨论】:

    • 好的,谢谢你的回答,这个程序以前使用本地 Web 服务,他们告诉我修改它以使用远程 Web 服务。我将改用 HttpClient。
    猜你喜欢
    • 2010-12-20
    • 1970-01-01
    • 1970-01-01
    • 2023-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多