-------------------------------------------------------------------------------------
<%@ Page language="C#" Debug="true"%>
<%@ Import namespace="System"%>
<%@ Import namespace="System.Text"%>
<%@ Import namespace="System.Net"%>
<%@ Import namespace="System.IO"%>
<%@ Import namespace="System.Web"%>
<%@ Import namespace="System.Xml"%>
<%
// This C# code in an ASP.net page (*.aspx) has been tested on Windows 2003 server
// with the .NET Framework version 1.1. In actual practice for design considerations,
// you may want to put the C# code in its own class and invoke it on this page with something
// like getConwayBOL (String bolRequest);
// Con-way authentication parameters
// ATTENTION *** you must replace the "userId" & "passWd" String values
// with your registered Con-way username and password
String userId = "userId";
String passWd = "passWd";
String authType = "basic";
// The target URI for the request. Choose one of the following - the 2nd is SSL-secured.
// Uri conwayUri = new Uri("http://www.Con-way.com/XMLj/X-BOL");
Uri conwayUri = new Uri("https://www.Con-way.com/XMLj/X-BOL");
//Format Today's Date into mm/dd/yy format
string today = DateTime.Today.Month.ToString() + "/" + DateTime.Today.Day.ToString()
+ "/" + DateTime.Today.Year.ToString().Remove(0, 2);
/* Build Bill of Lading Request XML String.
* In actual use, you would probably populate the BOL Request
* parameters (Weights, Classes, Zip Codes, etc.) from data submitted
* via an on-line order form or database.
* You could use the .NET XmlDocument class to build the XML, and then
* use the .InnerXml property to turn it into a String for the POST.
* For this sample we will just hard code some dummy data.
*/
String bolRequest="" +
"" + userId + "" +
"P" +
"" +
"" +
"3338889" +
"3338890" +
"3213A" +
"789283" +
"" +
"" +
"Alan Shipley" +
"1234 NE Main" +
"Portland" +
"OR" +
"97202" +
"503.450.6055" +
"web.support@Con-way.com" +
"" +
"" +
"" +
"Albert Cod" +
"1234 NE Main" +
"Portland" +
"OR" +
"97202" +
"" +
"4444.44" +
"" +
"" +
"883885" +
"503.450.6436" +
"web.support@Con-way.com" +
"" +
"- " +
"44" +
"667" +
"widget-arms" +
"775" +
"" +
"N" +
"
" +
"- " +
"11" +
"789" +
"cam-shafts" +
"100" +
"" +
"N" +
"
" +
"GUR" +
"DID" +
"DST" +
"TEST TEST TEST" +
"" +
"" +
"" + today + "" +
"4:00 pm" +
"7:00 pm" +
"Frank" +
"Franklin Arms" +
"(333)444-4321" +
"" +
"" +
"";
// Encode the Request String and set up the POST data
bolRequest = HttpUtility.UrlEncode(bolRequest);
String postData = "BOLrequest=" + bolRequest;
ASCIIEncoding encoding = new ASCIIEncoding();
byte [] postBuffer = encoding.GetBytes(postData);
// Set up the HTTP Request
HttpWebRequest wReq = (HttpWebRequest) WebRequest.Create(conwayUri);
wReq.ContentType="application/x-www-form-urlencoded";
wReq.ContentLength = postBuffer.Length;
wReq.Method="POST";
wReq.Timeout=10000;
wReq.KeepAlive = false;
NetworkCredential myCred = new NetworkCredential(userId, passWd);
CredentialCache myCache = new CredentialCache();
myCache.Add(conwayUri, authType, myCred);
wReq.Credentials = myCache;
wReq.PreAuthenticate = true;
Stream reqStream = wReq.GetRequestStream();
reqStream.Write(postBuffer,0,postBuffer.Length);
HttpWebResponse wResp = (HttpWebResponse) wReq.GetResponse();
Stream respStream = wResp.GetResponseStream ();
XmlTextReader xmlReader = new XmlTextReader(respStream);
XmlDocument xmlResponse = new XmlDocument();
xmlResponse.Load(xmlReader);
//The entire XML Response String
String respString = xmlResponse.InnerXml;
//Here is how to get a value out of a specific XML element:
String status = null;
XmlNodeList statusNodes = xmlResponse.GetElementsByTagName("Status");
//If there is no Status node, there will be an error node
if (statusNodes.Count > 0) {
status = statusNodes.Item(0).InnerText;
} else {
status = xmlResponse.GetElementsByTagName("Error").Item(0).InnerText;
}
%>
Sample .NET code for Con-way XML Bill of Lading
Sample .NET code for Con-way XML Bill of Lading
<%="Testing .NET execution ... Today is " + today%>
Here is the Bill of Lading Response XML output:
<%=respString%>
Here is the data extracted from an XML tag: BOL Request Status -- <%=status%>
<%
// Clean up resources
reqStream.Close();
xmlReader.Close();
respStream.Close();
wResp.Close();
%>
-------------------------------------------------------------------------------------