-------------------------------------------------------------------------------------
<%@ 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 getConwayRate(String rateRequest);
// 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-Rate");
Uri conwayUri = new Uri("https://www.Con-way.com/XMLj/X-Rate");
//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 Rate Request XML String.
* In actual use, you would probably populate the Rating 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 rateRequest = "" +
"97006" +
"33179" +
"P" +
"100" +
"" + today + "" +
"- " +
"775" +
"667" +
"
" +
"- " +
"100" +
"555" +
"
" +
"SSC" +
"DNC" +
"GUR" +
"";
// Encode the Request String and set up the POST data
rateRequest = HttpUtility.UrlEncode(rateRequest);
String postData = "RateRequest=" + rateRequest;
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 xmlRateQuote = new XmlDocument();
xmlRateQuote.Load(xmlReader);
//The entire XML Response String
String respString = xmlRateQuote.InnerXml;
//Here is how to get a value out of a specific XML element:
String netCharge = xmlRateQuote.GetElementsByTagName("NetCharge").Item(0).InnerText;
%>
Sample .NET code for Con-way XML Rating
Sample .NET code for Con-way XML Rating
<%="Testing .NET execution ... Today is " + today%>
Here is the RateQuote XML output:
<%=respString%>
Here is the data extracted from an XML tag: Shipping Charges: <%=netCharge%>
<%
// Clean up resources
reqStream.Close();
xmlReader.Close();
respStream.Close();
wResp.Close();
%>
-------------------------------------------------------------------------------------