“The request failed with an empty response” when c

2019-04-22 17:44发布

问题:

While calling a webservice hosted in a server from an aspx page am getting the error like "The request failed with an empty response".

code in my page

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) {

}

and in 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>

Is it a firewall problem.Any Suggestion?

回答1:

I know this is an old question, but we had the same exception happening in one of our integration environments:

System.Net.WebException: The request failed with an empty response

The issue was that when we upgraded the server hardware, we also switched all of our endpoints to be using HTTPS. The code that was calling the endpoints was not upgraded, so it was still using regular HTTP. Apparently this is the exception you get when you try to call an HTTPS service as HTTP. Hope this helps someone down the line.



回答2:

I would like to add to what Andacious stated. I was making a call to a web-service which was https but when I looked at the properties of the object making the call it actually was using http. So I specifically set the URL property.

I have a class called interchange which inherits from SoapHttpClientProtocol.

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

string x = interchangeWS.SomeMethod("someParameter");


回答3:

Sometimes it happens when pointing to an endpoint which is under LoadBalancer, what's happens is once you add the reference to the project (in VisualStudio) using HTTPS, then check the app.config file under the child and see if the endpoint URL is set to HTTP, then update it manually to HTTPS and you should be good. Hope it helps.



回答4:

make sure that service is https instead of http.Place https in web.config file also



回答5:

In client app.config or web.config first check web service URL , if your web Service URL having Secure Sockets Layer certificate , then add same Secure Sockets Layer enable URL to app.config or web.config . Like this "https://crm.XXXX.com/webServiceName.asmx"

System.Net.WebException: The request failed with an empty response