Quantcast
Viewing all articles
Browse latest Browse all 387

Error when using webrequest

Hello. I came across a strange error. My application has to unity3d module that connects to a web service using WebRequest. When I start in debug mode MonoDevelop(with attach to Unity3d) and my application try send the second request i get the following error: System.Net.WebException: The request timed out at System.Net.HttpWebRequest.EndGetResponse (IAsyncResult asyncResult) [0x00000] in :0 at System.Net.HttpWebRequest.GetResponse () [0x00000] in :0 at FooClient.Services.WebHttpClient.Execute (FooClient.Services.BaseRequest r) [0x00000] in :0 at FooClient.BL.RequestClient.ProcessRequest (FooClient.Services.BaseRequest r) [0x00000] in :0 First and third request web service are working normally If I run the application without debugging, then everything works fine. Here is the code request method protected override RequestResponse Execute(BaseRequest r) { string url = string.Format("{0}{1}/{2}", _serverUrl, r.Service.ToLower(), r.Action.ToLower()); if (r.Params != null && r.Params.Count > 0) { url = url + "?"; url = url + string.Join("&", r.Params.Where(c => c.Value != null).Select(c => c.Name + "=" + _encoder.Encode(c.Value.ToString()) ).ToArray()); } _log.Info(url); HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest; // Set some reasonable limits on resources used by this request request.MaximumAutomaticRedirections = 4; request.MaximumResponseHeadersLength = 4; request.Accept = "application/xml"; request.ContentType = "application/xml"; request.Timeout = 10000; request.KeepAlive = false; request.CookieContainer = new CookieContainer(); request.CookieContainer.Add(new Uri(url), new Cookie("Aspect", _context.ScreenAspect)); // Set credentials to use for this request. request.Credentials = CredentialCache.DefaultCredentials; using (HttpWebResponse response = request.GetResponse() as HttpWebResponse) { // Get the stream associated with the response. using (Stream receiveStream = response.GetResponseStream()) { // Pipes the stream to a higher level stream reader with the required encoding format. using (var readStream = new StreamReader(receiveStream, Encoding.UTF8)) { string result = readStream.ReadToEnd(); _log.Info(result); return new RequestResponse { StatusCode = response.StatusCode, Content = result }; } } } }

Viewing all articles
Browse latest Browse all 387

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>