when my below code is executing then some time i am getting The underlying connection was closed exception and root element is missing.
public ShippingAcceptResult ShippingAccept(string acceptDigestCode)
{
requestType = ShipRequestTypes.ShipAccept;
xmlRequest = new System.Xml.XmlDocument();
xmlRequest.LoadXml(@"<?xml version=""1.0""?>
<ShipmentAcceptRequest>
<Request>
<TransactionReference>
<CustomerContext>TR01</CustomerContext>
<XpciVersion>1.0001</XpciVersion>
</TransactionReference>
<RequestAction>ShipAccept</RequestAction>
<RequestOption>01</RequestOption>
</Request>
<ShipmentDigest>" + acceptDigestCode + "</ShipmentDigest></ShipmentAcceptRequest>");
byte[] bb = new System.Text.ASCIIEncoding().GetBytes(string.Format(XML_CONNECT, sAccessCode.Trim(), sUserId.Trim(), sPassword.Trim()));
System.IO.MemoryStream ms = new System.IO.MemoryStream();
ms.Write(bb, 0, bb.Length);
xmlRequest.Save(ms);
bb = ms.ToArray();
System.Net.WebClient wc = new System.Net.WebClient();
xmlRespone = new XmlDocument();
//System.Web.HttpContext.Current.Response.Write(System.Text.ASCIIEncoding.ASCII.GetString(wc.UploadData(UPS_URL, "POST", bb)));
string serverName = (testMode) ? "wwwcie" : "www";
serverName = string.Format(UPS_SERVICE_URL, serverName, ShipRequestTypes.ShipAccept);
xmlRespone.LoadXml(System.Text.ASCIIEncoding.ASCII.GetString(wc.UploadData(serverName, "POST", bb)));
//xmlRespone.Save(@"d:\shippingresponseAccept.xml");
return new ShippingAcceptResult(xmlRespone);
}
so i search google and found few SO link there. they are telling to set KeepAlive = false;
and i did it. here is the url from where i took the help https://stackoverflow.com/a/24719999/728750
also i checked few other SO link they are saying increase timeout. those url are
https://stackoverflow.com/a/6994391/728750 https://stackoverflow.com/a/3052637/728750 https://stackoverflow.com/a/1530717/728750
var request = (HttpWebRequest)WebRequest.Create(remoteUri);
request.Timeout = 30000;
so i just need to know if i set KeepAlive = false;
is it enough or also do i need to set Timeout too along with KeepAlive
please guide me. thanks