CodeVerge.Net Beta


   Explore    Item Entry    Members      Register  Login  
NEWSGROUP
.NET
Algorithms-Data Structures
Asp.Net
C Plus Plus
CSharp
Database
HTML
Javascript
Linq
Other
Regular Expressions
VB.Net
XML

Free Download:




Zone: > NEWSGROUP > Asp.Net Forum > starter_kits_and_source_projects.commerce_starter_kit Tags:
Item Type: NewsGroup Date Entered: 5/7/2004 1:36:04 AM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
(NR, 0)
XPoints: N/A Replies: 0 Views: 57 Favorited: 0 Favorite
Can Reply:  No Members Can Edit: No Online: Yes
1 Items, 1 Pages 1 |< << Go >> >|
mnswiftone
Asp.Net User
UPS XML Rate Query C# Code Sample - Click Here5/7/2004 1:36:04 AM

0/0

I know many people are looking for help developing their own XML code - like myself, I have tried asking and seen many recommendations to buy a control - but we learn from typing - not just plugging in a fix...

So - I finally figured this out myself with some trial and error - and I had promised to share when I had figured it out...
Disclaimer: I am fairly new to C# so it may not be in perfect format. No warranties or guarantees are provided. Code is provided as-is - use at your own risk... :)

I am unemployed - so if anyone is feeling grateful (or hiring) - feel free to email and thank me (I can accept donations too...). I should note - I did ask many, one person sent me his VB code - far from complete, I didn't use or even look at it since it was not for rate quotes and VB uses totally different calls vs C# which I am working on now.

This should be enough to get your started, I left in parts (commented out) from the sample that caused the sample to fail with UPS error 250005 as I have seen others with this error - might be the same failing code. (Error handling is done in the parser code).

If anyone needs help with the parser code - post here and I'll help - but that should be easy as I did it from the MS examples and the UPS .pdf file.

Sample code:

//------------------------------------------------------------
// UPS XML Rate Query Example in C#
// by Todd Nelson
//
// Method: string sendUPSXMLquery(string url,string reqXml)
// This method should be added to a Component class file - not in codebehind
//
// Returns:
// Success: XML string ready to be parsed
// Failure: error code in 'resultStr' XML string from UPS -or-
// Exception code from catch block
//
// Input:
// url - url i.e. "https://wwwcie.ups.com/ups.app/xml/Rate"
// reqXml - entire XML string like UPS sample
//
// sample reqXml string =
// "<?xml version=\"1.0\"?>"+
// "<AccessRequest xml:lang=\"en-US\">"+
// "<AccessLicenseNumber>YOURACCESSLICENSE</AccessLicenseNumber>" +
// "<UserId>YOURUPSUSERID</UserId>" +
// "<Password>YOURUPSPW</Password>" +
// "</AccessRequest>" +
// "<?xml version=\"1.0\"?>"+
// "<RatingServiceSelectionRequest xml:lang=\"en-US\">"+
// "<Request>"+
// "<TransactionReference>"+
// ... rest same as sample UPS string from .pdf file
//------------------------------------------------------------
internal static string sendUPSXMLquery(string url,string reqXml)
{
WebResponse result = null;
string resultStr="";
try
{
// This paragraph from MS Help file...
// The WebRequest and WebResponse classes use Secure Sockets Layer (SSL)
// to communicate with hosts that support SSL automatically.
// The decision to use SSL is made by the WebRequest class,
// based on the URI it is given.
// If the URI begins with "https:" then SSL is used;
// if the URI begins with "http:" SSL is not used.
// ...end MS Help file comment
WebRequest req = WebRequest.Create(url);
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
byte[] SomeBytes = null;

// This sample taken from MS Example file - but:
// Rest of all commented area here prevented UPS code from executing
// apparently changed XML to a non-compatible format
// guess - UPS cannot handle reserved char replacement routine
// left it here commented so readers will know - if they
// had tried this MS example code - Now they know why it did not work
//
// StringBuilder UrlEncoded = new StringBuilder();
// Char[] reserved = {'?', '=', '&'};

if (reqXml != null)
{
//
// int i=0, j;
// while(i<reqXml.Length)
// {
// j=reqXml.IndexOfAny(reserved, i);
// if (j==-1)
// {
// UrlEncoded.Append(HttpUtility.UrlEncode(reqXml.Substring(i, reqXml.Length-i)));
// break;
// }
// UrlEncoded.Append(HttpUtility.UrlEncode(reqXml.Substring(i, j-i)));
// UrlEncoded.Append(reqXml.Substring(j,1));
// i = j+1;
// }

SomeBytes = Encoding.UTF8.GetBytes(reqXml.ToString());

req.ContentLength = SomeBytes.Length;
Stream newStream = req.GetRequestStream();
newStream.Write(SomeBytes, 0, SomeBytes.Length);
newStream.Close();
}
else
{
req.ContentLength = 0;
}

result = req.GetResponse();
Stream ReceiveStream = result.GetResponseStream();
Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
StreamReader sr = new StreamReader( ReceiveStream, encode );

Char[] read = new Char[256];
int count = sr.Read( read, 0, 256 );

while (count > 0)
{
String str = new String(read, 0, count);
resultStr += str;
count = sr.Read(read, 0, 256);
}
}
catch(Exception e)
{
resultStr = "Error: " + e.ToString();
}
finally
{
if ( result != null )
{
result.Close();
}
}

return resultStr;
}



Have Fun!
Todd Nelson
[email protected]
1 Items, 1 Pages 1 |< << Go >> >|


Free Download:


Web:
Freelance Project | Intergrate Ups Shipping Rates Ups.com uses XML to request and receive this data. 3. I can provide you with the tools from the ... However, you can click here to see the related document. ...
UPS, USPS, Fedex shipping rate calculator | FreeLance Home Jobs After I click submit, I want to query and get responses from USPS, UPS, .... XML shipping calculator. I seek code to get instant shipping quotes from the ...
osCommerce Community Support Forums > New UPS XML Shipping Module ... UPS XML uses two tools: Rates & Services and Time in Transit. ..... view the full version with more information, formatting and images, please click here. ...
Shipping Estimator & UPS module for U.S. store - Zen Cart Support Just click here Are you using the latest? .... You would need to use the UPSXML which is in the Wiki in the 3rd Party Downloads . ...
Introduction to XForms, Part 3: Using actions and events Sep 26, 2006 ... It replaces traditional HTML forms with an XML data model and ... Click here to begin ...
shopping cart software Sep 19, 2008 ... The Volusion UPS Worldship Auto XML Import Application is a free, ... Click the "URL with Query String and General Information for Importing ...
Parse mathematical expressions with JEP - Program - Java C C++ ... Sep 23, 2008 ... Our hourly rate is very very low. 2. We are top Adobe Flex outsourcing service provider. 3. ... more. Click here to leave your comment ...
ASP.NET Shipping Web Service for UPS Shipping Rates, Shipping ... Country and Region mappings XML files for all shipping carriers. eShip can be integrated to your code and start shipping rate calculation, generate labels ...
Web Programming Answers You’re here because you want to run UPS XML for Zen Cart with zones. ...... Start a new query. Open c:\aaweb\personal\app_data\personal-add.sql. ...
SQL Server Profiler (://URLFAN) Click here to view stats and graphs for kevinlewisblog.com ... I decided to cleanup my old UPS Webservice Rate Calculation code, and implement some XML ...




Search This Site:










aspnet_paths table not getting populated using sqlmembershipprovider

defaultcredentials

could not load type microsoft.web.ui.webcontrols.basepostbackcontrol

using drop downs in a composit control

programmatically setting the selected node in sitemapdatasource

hide "site" skin and container folders from file manager.

security features

different css sheet for admin vs. portal?

3.1 to 3.2 upgrade issue.

master page problem

sqldatareader connection

sys.webforms.pagerequestmanagerservererrorexception

accessing sql server roles from c# code behind

no silent checkout/prompt for .aspx.vb files

how to force a user to log out programmatically - bug????

customizing the contacts web part...

configuration tool role management + membershipadprovider error

system hardware requirements for intranet

tttgallery and "the page cannot be displayed"

inter module communication

about tabstrip

link to launch a popup window

web.sitemap : menu root items

web application migration wizard not being invoked

nested masterpage problem

flexible grid forms module [dnn 2.x]

firefox, tables, and master pages

need help on masterpage to hide couple of links in a contentplace holder when a sepcific page rendered in the contentplaceholder?

md5 encryption in login

skin problem panes missing on the default page

 
All Times Are GMT