UPS API learning to post XML, and retrieving error status from server. Need someone to check code.

Hi,
I'm trying to figure out how to implement UPS API tools into ASP.NET. I already have Access Key, ID + password from www.ups.com. First of all I would like check authentification status. I have find this code from microsoft.com, and past necessary information.

Server response:
<?xml version="1.0"?>
<AddressValidationResponse>
<Response>
<TransactionReference>
</TransactionReference>
<ResponseStatusCode>0</ResponseStatusCode>
<ResponseStatusDescription>Failure</ResponseStatusDescription>
<Error>
<ErrorSeverity>Hard</ErrorSeverity>
<ErrorCode>250005</ErrorCode>
<ErrorDescription>No Access Identification provided</ErrorDescription>
</Error>
</Response>
</AddressValidationResponse>

Open in new window


Code behind:
Imports System
Imports System.IO
Imports System.Net
Imports System.Text
Partial Class _Default
    Inherits System.Web.UI.Page
    Public Sub Main()
        Dim myxml As String = ""
        myxml = "<?xml version=""1.0""?>"
        myxml = "<AccessRequest xml:lang=""en-US"">"
        myxml = "<merchantAuthentication>"
        myxml = "<AccessLicenseNumber>2**************5</AccessLicenseNumber>"
        myxml = "<UserId>A****3</UserId>"
        myxml = "<Password>D******4</Password>"
        myxml = "</AccessRequest>"

        Try
            ' Create a request using a URL that can receive a post. 
            Dim request As WebRequest = WebRequest.Create("https://wwwcie.ups.com/ups.app/xml/AV")
            ' Set the Method property of the request to POST.
            request.Method = "POST"
            ' Create POST data and convert it to a byte array.
            Dim postData As String = myxml
            Dim byteArray As Byte() = Encoding.UTF8.GetBytes(postData)
            ' Set the ContentType property of the WebRequest.
            request.ContentType = "application/x-www-form-urlencoded"
            ' Set the ContentLength property of the WebRequest.
            request.ContentLength = byteArray.Length
            ' Get the request stream.
            Dim dataStream As Stream = request.GetRequestStream()
            ' Write the data to the request stream.
            dataStream.Write(byteArray, 0, byteArray.Length)
            ' Close the Stream object.
            dataStream.Close()
            ' Get the response.
            Dim response As WebResponse = request.GetResponse()
            ' Display the status.
            Console.WriteLine(CType(response, HttpWebResponse).StatusDescription)
            ' Get the stream containing content returned by the server.
            dataStream = response.GetResponseStream()
            ' Open the stream using a StreamReader for easy access.
            Dim reader As New StreamReader(dataStream)
            ' Read the content.
            Dim responseFromServer As String = reader.ReadToEnd()
            ' Display the content.
            TextBox1.Text = responseFromServer
            ' Clean up the streams.
            reader.Close()
            dataStream.Close()
            response.Close()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

    End Sub

    Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Main()
    End Sub
End Class

Open in new window


Thank you in advance for help!
dejandejanovicAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David Johnson, CD, MVPOwnerCommented:
Which API are you using? As there are two parts.. a sent item and a response.

"https://wwwcie.ups.com/ups.app/xml/AV"

confirm the address is correct.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dejandejanovicAuthor Commented:
Well, all APIs have first request authentification, successful communication with this wwwcie (UPS testing enviroment) server.
So, I have start with just first part of below XML, with  authentification, which I have pickup from ups.com api zip file.
I have also found ups common error descriptions. And, for my error is:
250005 - No Access and Authentication Credentials provided

Do you have any idea what could be wrong?
Did you use your own UPS access key, ID +pass?
Did you use your own code? If yes, is it possible to post here?

Template code:
<?xml version="1.0"?>
<AccessRequest xml:lang="en-US">
  <AccessLicenseNumber>YourLicenseNumber</AccessLicenseNumber>
  <UserId>YourUserID</UserId>
  <Password>YourPassword</Password>
</AccessRequest>
<?xml version="1.0"?>
<AddressValidationRequest xml:lang="en-US">
  <Request>
    <TransactionReference>
      <CustomerContext>Your Test Case Summary Description</CustomerContext>
      <XpciVersion>1.0</XpciVersion>
    </TransactionReference>
    <RequestAction>XAV</RequestAction>
    <RequestOption>3</RequestOption>
  </Request>
    <AddressKeyFormat>
    <AddressLine>AIRWAY ROAD SUITE 7</AddressLine>	
    <PoliticalDivision2>SAN DIEGO</PoliticalDivision2>
	<PoliticalDivision1>CA</PoliticalDivision1>
    <PostcodePrimaryLow>92154</PostcodePrimaryLow>
    <CountryCode>US</CountryCode>
  </AddressKeyFormat>
</AddressValidationRequest>

Open in new window

0
dejandejanovicAuthor Commented:
I was expect more help here.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.