FedEx 地址验证 Web 服务出现问题

发布于 2024-08-09 06:17:46 字数 5120 浏览 6 评论 0原文

我正在尝试开始使用 FedEx 的地址验证服务,但在使用 FedEx 自己的演示应用程序时遇到了障碍。

这是应用程序中的代码:

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.ProposedAddressDetails 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

似乎将请求对象发送到 Web 服务,但“回复”对象返回“Nothing”。如果我编写代码我可以理解,但是天哪......他们甚至无法让自己的代码工作?有其他人看到/解决了这个问题吗?

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.ProposedAddressDetails 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

伴随着你 2024-08-16 06:17:46

该应用程序显示出一些明显的迹象,表明它首先是用 C# 编写的,后来转换为 VB.Net。具体来说:

Dim request As AddressValidationRequest = New AddressValidationRequest()

可以简化为:

Dim request As New AddressValidationRequest()

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

可以用多种方式编写,但至少我希望纯 VB 程序员知道 AndAlso 而不是 And<> 而不是 Not ... = ...。最后:

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

创建一个新对象并立即丢弃它。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文