Reputation: 65
I'm facing with an exception when I send data to Sap B1 Service Layer via Asp.Net HttpWebRequest
.
We were using https://xx.xx.x.xxx:50000/b1s/v1/ address for service layer operations but then we switched to http://xx.xx.x.xxx:50001/b1s/v1/ address (load balancing ports).
This solved some issues but now we are facing this error:
The underlying connection was closed: The connection was closed unexpectedly
The error only occurs in write methods like "POST" and "PATCH". Interestingly the error rarely occurs after first 2 to 3 requests.
I send the HttpWebRequest
request like below and I copied this settings from SAP B1 Sample Project also tried many different settings but couldn't solve the problem. Thank you.
var request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "PATCH"
request.Accept = "application/json;odata=minimalmetadata";
request.KeepAlive = true;
request.ServicePoint.Expect100Continue = false;
request.AllowAutoRedirect = true;
request.ContentType = "application/json;odata=minimalmetadata;charset=utf8";
request.Timeout = 10000000;
request.Headers.Add(HttpRequestHeader.Cookie, "B1SESSION=" + GetSessionId());
I also have below settings in my Global.asax.cs
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12 | SecurityProtocolType.Ssl3;
ServicePointManager.ServerCertificateValidationCallback +=
(sndr, cert, chain, sslPolicyErrors) => true;
Upvotes: 1
Views: 4104
Reputation: 65
We found that the main cause of "The underlying connection was closed: The connection was closed unexpectedly." error is about lack of hardware resources. After we switched to more powerful server which uses the same configuration for service layer with old machine(dev environment) the problem was solved.
Upvotes: 0