我只是将xml传递给UPS Web服务,Web服务返回一些数据。一段时间我收到错误缺少根元素这里是我的例程代码,它会抛出此错误。请指导我如何解决它。
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);
}
最有趣的是如果我在例程的开头添加了thread.sleep(),那么就不会发生错误。请详细告诉我代码中存在问题的地方。感谢
此行抛出错误xmlRespone.LoadXml(System.Text.ASCIIEncoding.ASCII.GetString(wc.UploadData(serverName, "POST", bb)));