HttpWebRequest - underlying connection was closed

  • 6 March 2007
  • 1 reply
  • 10 views

Badge
I am attempting to use the HttpWebRequest object to call a form dynamically. When testing the code via an aspx page everything works fine. But when I attempt to execute the code via K2, I get the following error

System.Net.WebException: The underlying connection was closed: The remote name could not be resolved.
at System.Net.HttpWebRequest.CheckFinalStatus()
at System.Net.HttpWebRequest.EndGetRequestStream(IAsyncResult asyncResult)
at System.Net.HttpWebRequest.GetRequestStream()

The form is on the same machine as the K2 server.

The code is identical on both the form and in the K2 ClientEvent


Any thoughts or hints?
System.Net.HttpWebRequest objRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(URI);
objRequest.Method = "POST";
objRequest.ContentLength = vars.Length;
objRequest.ContentType = "application/x-www-form-urlencoded";
objRequest.CookieContainer = new System.Net.CookieContainer();
// objRequest.Credentials = System.Net.CredentialCache.DefaultCredentials;

objRequest.Credentials = new System.Net.NetworkCredential(username, password,domain);

System.IO.StreamWriter myWriter = new System.IO.StreamWriter(objRequest.GetRequestStream());
myWriter.Write(urlVariables);
myWriter.Close();

1 reply

Badge +6
Try running the K2 Server in console mode and using Console.Writeline statements in the Repair Error window determined the failure was occurring in the calls being made.

Depending on your results/situation, you may find the actual call to the web service was throwing the error as <mysite.mydomain.com> can not be resolved from the K2 server (if it resolved fine from other client machines).

Adding a hosts file entry for <mysite.mydomain.com> on the K2 Server and verify it works with 'repair all' process instances that are currently in error state.

You may also want to compare environments and ensure the requisite .Net Framework is installed.

You may also want to confirm the URL being set is accurate.

Lastly, if something works in one environment but not another, check:
- the user context (using the logged in user). Log in as the 'successful' user account in the broken environment and check the results.
- differences between environments (Framework versions, permissions, configs, etc.)

I hope this helps.

Reply