This is surya. . Im doing a .net client application to make a REST Call to netsuite and POST the Data from netsuite.
The Restlet(Netsuite) will run for 5 mins(max possible time).And Coming to my problem, whenever i trigger the Restlet(netsuite) from C# .NET Application,the restlet is called and it will start its execution process.But the connection which the C# .NET Client application has established with the RESTlet is getting closed exactly after 2mins without giving any response.And the response will be given once the RESTlet is finished.But the problem is m getting the error "The underlying Connection was Closed.The Connection was closed Unexpectedly" .And at the backend the RESTlet will run for 5mins as it will run for 5mins.And i have tried all the possible ways to increase the connection TimeLimit,including keepAlive,protocolversion,etc.. Can anyone come up with a clear solution of how to solve this
Here is my Code:
Expand|Select|Wrap|Line Numbers
- Dictionary<string, string> NS_SS_fmt = new Dictionary<string, string>();
- myWebRequest = (HttpWebRequest)WebRequest.Create(this.rest_url);
- myWebRequest.ContentType = "application/json";
- myWebRequest.Method = "POST";
- myWebRequest.Timeout = 1200000; //20mins
- myWebRequest.Credentials = CredentialCache.DefaultCredentials;
- //myWebRequest.Proxy = new WebProxy("127.0.0.1", 8888);
- //myWebRequest.ServicePoint.ConnectionLeaseTimeout = 300000;
- //myWebRequest.KeepAlive = true;
- //myWebRequest.ServicePoint.MaxIdleTime = 300000;
- //myWebRequest.PreAuthenticate = true;
- //myWebRequest.ProtocolVersion = HttpVersion.Version11;
- //myWebRequest.AllowAutoRedirect = true;
- //myWebRequest.MaximumAutomaticRedirections = 10;
- //myWebRequest.ReadWriteTimeout = 500000;
- this.setHeader();
- NS_SS_fmt.Add("requestType", rec_type);
- this.sendHttpRequest(NS_SS_fmt);
- string response = this._getHttpResponse();
- public void setHeader()
- {
- // Nothing But Authentication Header
- myWebRequest.Headers.Add("User-Agent-x:SuiteScript-Call");
- myWebRequest.Headers.Add("Authorization:NLAuth nlauth_account="+this.netsuite_acc_name+",nlauth_email="+this.netsuite_email+",nlauth_signature="+this.netsuite_pwd+",nlauth_role="+this.netsuite_role);
- logger.Info("Netsuite Header Credential Done");
- }public void sendHttpRequest(Dictionary<string, string> requestPair) // to netsuite Rest
- {
- try
- {
- var json_object = new JavaScriptSerializer().Serialize(requestPair);
- using (var streamWriter = new StreamWriter(myWebRequest.GetRequestStream())) { streamWriter.Write(json_object); }
- }
- catch (Exception e)
- {
- System.Environment.Exit(2);
- }
- }
- string response = (HttpWebResponse)myWebRequest.GetResponse();//My connection will get closed at this place while getting the response