开发者

Problem with FedEx Address validation web service

I'm trying to get started with Fedex'es Address validation service and I'm running into a road block with FedEx's own demo application.

This is the code in there app:

Sub Main()

    ''# Build a AddressValidationRequest object
    Dim request As AddressValidationRequest = New AddressValidationRequest()

    Console.WriteLine("--- Setting Credentials ---")
    request.WebAuthenticationDetail = New WebAuthenticationDetail()
    request.WebAuthenticationDetail.UserCredential = New WebAuthenticationCredential()
    request.WebAuthenticationDetail.UserCredential.Key = "###" ''# Replace "XXX" with the Key
    request.WebAuthenticationDetail.UserCredential.Password = "###" ''# Replace "XXX" with the Password

    Console.WriteLine("--- Setting Account Information ---")
    request.ClientDetail = New ClientDetail()
    request.ClientDetail.AccountNumber = "###" ''# Replace "XXX" with clients account number
    request.ClientDetail.MeterNumber = "###" ''# Replace "XXX" with clients meter number
    request.TransactionDetail = New TransactionDetail()
    request.TransactionDetail.CustomerTransactionId = "Address Validation v2 Request using VB.NET Sample Code" ''# This is just an echo back 
    request.Version = New VersionId()

    request.RequestTimestamp = DateTime.Now

    Console.WriteLine("--- Setting Validation Options ---")
    request.Options = New AddressValidationOptions()
    request.Options.CheckResidentialStatus = True
    request.Options.MaximumNumberOfMatches = 5
    request.Options.StreetAccuracy = AddressValidationAccuracyType.LOOSE
    request.Options.DirectionalAccuracy = AddressValidationAccuracyType.LOOSE
    request.Options.CompanyNameAccuracy = AddressValidationAccuracyType.LOOSE
    request.Options.ConvertToUpperCase = True
    request.Options.RecognizeAlternateCityNames = True
    request.Options.ReturnParsedElements = True

    Console.WriteLine("--- Address 1 ---")
    request.AddressesToValidate = New AddressToValidate(1) {New AddressToValidate(), New AddressToValidate()}
    request.AddressesToValidate(0).AddressId = "WTC"
    request.AddressesToValidate(0).Address = New Address()
    request.AddressesToValidate(0).Address.StreetLines = New String(0) {"10 FedEx Parkway"}
    request.AddressesToValidate(0).Address.PostalCode = "38017"
    request.AddressesToValidate(0).CompanyName = "FedEx Services"

    Console.WriteLine("--- Address 2 ---")
    request.AddressesToValidate(1).AddressId = "Kinkos"
    request.AddressesToValidate(1).Address = New Address()
    request.AddressesToValidate(1).Address.StreetLines = New String(0) {"50 N Front St"}
    request.AddressesToValidate(1).Address.PostalCode = "38103"
    request.AddressesToValidate(1).CompanyName = "FedEx Kinkos"

    Dim addressValidationService As AddressValidationService.AddressValidationService = New AddressValidationService.AddressValidationService
    ''#

    Try
        ''# This is the call to the web service passing in a AddressValidationRequest and returning a AddressValidationReply
        Console.WriteLine("--- Sending Request..... ---")
        Dim reply As New AddressValidationReply()
        reply = addressValidationService.addressValidation(request)


        Console.WriteLine("--- Processing request.... ---")
        ''#This is where I get the error 
        If (Not reply.HighestSeverity = NotificationSeverityType.ERROR) And (Not reply.HighestSeverity = NotificationSeverityType.FAILURE) Then
            If (Not reply.AddressResults Is Nothing) Then
                For Each result As AddressValidationResult In reply.AddressResults
                    Console.WriteLine("Address Id - " + result.AddressId)
                    Console.WriteLine("--- Proposed Details ---")
                    If (Not result.Propo开发者_运维百科sedAddressDetails Is Nothing) Then
                        For Each detail As ProposedAddressDetail In result.ProposedAddressDetails
                            Console.WriteLine("Score - " + detail.Score)
                            Console.WriteLine("Address - " + detail.Address.StreetLines(0))
                            Console.WriteLine("          " + detail.Address.StateOrProvinceCode + " " + detail.Address.PostalCode + " " + detail.Address.CountryCode)
                            Console.WriteLine("Changes -")
                            For Each change As AddressValidationChangeType In detail.Changes
                                Console.WriteLine(change.ToString())
                            Next
                            Console.WriteLine("")
                        Next
                    End If
                    Console.WriteLine("")
                Next
            End If
        Else
            For Each notification As Notification In reply.Notifications
                Console.WriteLine(notification.Message)
            Next
        End If
    Catch e As SoapException
        Console.WriteLine(e.Detail.InnerText)
    Catch e As Exception
        Console.WriteLine(e.Message)
    End Try
    Console.WriteLine("Press any key to quit !")
    Console.ReadKey()
End Sub

It seems to send the request object to the web service, but the"reply" object is returned with "Nothing". I could understand if I wrote the code, but good god... they can't even get their own code to work? Has anyone else seen/fixed this problem?


The app shows some tell-tale signs of having been first written in C# and then converted to VB.Net later. Specifically:

Dim request As AddressValidationRequest = New AddressValidationRequest()

Could be shortened to simply:

Dim request As New AddressValidationRequest()

.

If (Not reply.HighestSeverity = NotificationSeverityType.ERROR) And (Not reply.HighestSeverity = NotificationSeverityType.FAILURE) Then

could be written several ways, but at very least I would expect a pure-VB programmer to know of either AndAlso instead of And or <> instead of Not ... = .... Finally:

Dim reply As New AddressValidationReply()
reply = addressValidationService.addressValidation(request)

creates a new object and promptly discards it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜