Click here to Skip to main content
Licence CPOL
First Posted 26 Oct 2007
Views 47,551
Downloads 786
Bookmarked 24 times

UPS Address Validation Sample With ASP.NET and C#

By | 26 Oct 2007 | Article
A UPS Online Tool address validation sample with ASP.NET and C#.

Screen Shot

Introduction

I'm right now working on UPS online tool integration with my e-commerce web site. It is quite difficult to find sample source code for use with .NET. I created this article for .NET users who want to integrate their e-commerce web sites with the UPS Online Tool.

See details at UPS Online Tool.

Using the code

To use UPS address validation, you have to register a UPS account at UPS Account Register and request for a UPS access key at Get UPS Access Key.

To run my sample website, you have to replace your UPS account for user ID, password, and access key in the web.config.

<!-- Web.Config -->
<add key="AccessLicenseNumber" value="xxxxxxxxxxxxxxxx"/>
<add key="UserId" value="xxxxxx"/>
<add key="Password" value="xxxxxx"/>

This is the main code for the request address validation with the UPS online tool service.

// Create Request to UPS online tool address validation service
ASCIIEncoding encodedData = new ASCIIEncoding();
byte[] byteArray = encodedData.GetBytes(requestText);

// open up da site
HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(url);
wr.Method = "POST";
wr.KeepAlive = false;
wr.UserAgent = "Benz";
wr.ContentType = "application/x-www-form-urlencoded";
wr.ContentLength = byteArray.Length;
try
{
    // send xml data
    Stream SendStream = wr.GetRequestStream();
    SendStream.Write(byteArray, 0, byteArray.Length);
    SendStream.Close();
    // get da response
    HttpWebResponse WebResp = (HttpWebResponse)wr.GetResponse();

    using (StreamReader sr = new StreamReader(WebResp.GetResponseStream()))
    {
        result = sr.ReadToEnd();
        sr.Close();
    } 

    WebResp.Close();
}
catch (Exception ex)
{
    // Unhandle exception occure
    result = ex.Message;
}

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Benz CPE



Thailand Thailand

Member

.NET developer

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionNo Access Identification provided PinmemberAlexander B. Deyto21:59 1 Nov '11  
GeneralMy vote of 5 PinmemberDougVarga15:49 6 Nov '10  
GeneralUnable to connect to the remote server Pinmemberrishi_narula0:10 17 Feb '09  
GeneralRe: Unable to connect to the remote server PinmemberMember 37981997:07 10 Nov '09  
QuestionHow to get the shipping method form ups by different zip code? PinmemberMember 37832578:23 11 Aug '08  
GeneralCalculate Shipping rates for canda postal code PinmemberAyesha rana23:05 27 Jul '08  
QuestionUsing the address field? PinmemberSuperJason2k7:45 6 Mar '08  
AnswerRe: Using the address field? PinmemberBeaniiman9:30 20 May '08  
GeneralRe: Using the address field? PinmemberMember 26864139:45 14 Sep '10  
GeneralUPS online tools PinmemberRon Yam10:08 8 Jan '08  
General[Message Deleted] Pinmembersara5510:46 28 Jul '08  
GeneralRe: UPS online tools Pinmembersara556:33 30 Jul '08  
GeneralRe: UPS online tools Pinmembersara5512:25 28 Jul '08  
QuestionUPS Shipping Tool PinmemberGfw1:38 26 Oct '07  
AnswerRe: UPS Shipping Tool PinmemberGevorg5:48 26 Oct '07  
GeneralRe: UPS Shipping Tool PinmemberGfw23:54 27 Oct '07  
AnswerRe: UPS Shipping Tool PinmemberBenz CPE17:18 28 Oct '07  
GeneralRe: UPS Shipping Tool PinmemberGfw6:00 30 Oct '07  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120517.1 | Last Updated 26 Oct 2007
Article Copyright 2007 by Benz CPE
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid