调用Web服务时"请求失败并显示空响应"

bal*_*569 11 c# asp.net proxy web-services

从aspx页面调用托管在服务器中的Web服务时,会收到类似"请求失败,响应为空"的错误.

我页面中的代码

try {
    HttpWebRequest request1 = (HttpWebRequest)WebRequest.Create("https://login.erp.com/rodeprovisioning/provisioning.asmx");
    request1.Accept = "text/xml";
    request1.Method = "POST";
    WebProxy proxyObject = new System.Net.WebProxy("http://10.0.0.1:8080/", true);
    request1.Proxy.Credentials = CredentialCache.DefaultCredentials;
    string sReturnValue = null;
    if (string.IsNullOrEmpty(Session["Test"])) {
        sReturnValue = callservice();
        if (sReturnValue == "Success") {
            ErrorLabel.Text = sReturnValue;
            Session["Test"] = "True";
        } else {
            ErrorLabel.Text = sReturnValue;
        }
    }

} catch (Exception ex) {

}
Run Code Online (Sandbox Code Playgroud)

并在web.config中

<system.net>
    <authenticationModules>
      <add type = "System.Net.DigestClient" />
      <add type = "System.Net.NegotiateClient" />
      <add type = "System.Net.KerberosClient" />
      <add type = "System.Net.NtlmClient" />
      <add type = "System.Net.BasicClient" />
    </authenticationModules>
    <connectionManagement>
      <add address = "*" maxconnection = "2" />
    </connectionManagement>
    <defaultProxy>
      <proxy usesystemdefault="True"   bypassonlocal = "True"   />
    </defaultProxy>
    <webRequestModules>
      <add prefix = "http"   type = "System.Net.HttpRequestCreator"        />
      <add prefix = "https"  type = "System.Net.HttpRequestCreator"        />
      <add prefix = "file"   type = "System.Net.FileWebRequestCreator"         />
    </webRequestModules>
  </system.net>
Run Code Online (Sandbox Code Playgroud)

这是防火墙问题.有什么建议吗?

And*_*ous 26

我知道这是一个老问题,但我们在其中一个集成环境中遇到了同样的异常:

System.Net.WebException: The request failed with an empty response
Run Code Online (Sandbox Code Playgroud)

问题在于,当我们升级服务器硬件时,我们还将所有端点切换为使用HTTPS.调用端点的代码未升级,因此仍使用常规HTTP.显然,这是您尝试将HTTPS服务作为HTTP调用时获得的异常.希望这可以帮助有人下线.


小智 7

我想补充一下Andacious说的话.我正在调用一个https的Web服务,但当我查看调用它的对象的属性时,它实际上是使用http.所以我专门设置了URL属性.

我有一个名为interchange的类,它继承自SoapHttpClientProtocol.

interchangeWS = new InterchangeWS();
interchangeWS.Url = "https://somesite/interchange.asmx";

string x = interchangeWS.SomeMethod("someParameter");
Run Code Online (Sandbox Code Playgroud)