Fedex 地址验证问题 Web 参考

发布于 2024-09-14 19:22:38 字数 10258 浏览 7 评论 0原文

我正在尝试让示例 FedEx 地址验证应用程序在 C# 中工作。在联系我的 FedEx 技术联系人并让他在我的测试帐户上激活地址验证(显然它被认为是需要额外权限的高级服务)后,我能够编译并运行示例应用程序。

但是,在给定的设置下,我没有得到预期的结果...

request.Options.ConvertToUpperCase = true;
request.Options.CheckResidentialStatus = true;

根据这些标志,我希望地址以大写形式返回,并且能够检查 Residential 或 ResidentialStatus 属性以确定商业还是住宅住宅。两者都没有发生。

因此,我安装了 Fiddler 来查看正在发生的确切 SOAP 交换,并发现除了一个属性 MaximumNumberOfMatches 之外,出站选项标记并未填充。

我应该在 Visual Studio 创建的 Reference.cs 文件中检查什么内容吗?我没有看到任何不正常的情况,但正在发生的事情阻止了某些属性的序列化。

--编辑--

根据下面的建议更新了我的代码。不幸的是,它仍然只填充 2 个选项参数。我在下面添加了 C# 设置代码和出站/入站 SOAP 请求。谁能想到 SOAP 请求中未发送其余选项的原因吗?

AddressValidationRequest request = new AddressValidationRequest();
            //
            request.WebAuthenticationDetail = new WebAuthenticationDetail();
            request.WebAuthenticationDetail.UserCredential = new WebAuthenticationCredential();
            request.WebAuthenticationDetail.UserCredential.Key = "XXX-KEY-XXX"; // Replace "XXX" with the Key
            request.WebAuthenticationDetail.UserCredential.Password = "XXX-PWD-XXX"; // Replace "XXX" with the Password
            //
            request.ClientDetail = new ClientDetail();
            request.ClientDetail.AccountNumber = "XXX-ACCT#-XXX"; // Replace "XXX" with client's account number
            request.ClientDetail.MeterNumber = "XXX-MTR#-XXX"; // Replace "XXX" with client's meter number
            //
            request.TransactionDetail = new TransactionDetail();
            request.TransactionDetail.CustomerTransactionId = "***Address Validation v2 Request using VC#***"; // This is just an echo back 
            //
            request.Version = new VersionId(); // Creates the Version element with all child elements populated
            //
            request.RequestTimestamp = DateTime.Now;
            //
            request.Options = new AddressValidationOptions();
            request.Options.CheckResidentialStatus = true;
            request.Options.CheckResidentialStatusSpecified = true;
            request.Options.VerifyAddresses = true;
            request.Options.MaximumNumberOfMatches = "5";
            request.Options.StreetAccuracy = AddressValidationAccuracyType.MEDIUM;
            request.Options.DirectionalAccuracy = AddressValidationAccuracyType.MEDIUM;
            request.Options.CompanyNameAccuracy = AddressValidationAccuracyType.MEDIUM;
            request.Options.ConvertToUpperCase = true;
            request.Options.RecognizeAlternateCityNames = true;
            request.Options.ReturnParsedElements = true;
            //
            request.AddressesToValidate = new AddressToValidate[2];
            request.AddressesToValidate[0] = new AddressToValidate();
            request.AddressesToValidate[0].AddressId = "Kimmel";
            request.AddressesToValidate[0].Address = new Address();
            request.AddressesToValidate[0].Address.StreetLines = new String[1] { "425 Morningside Dr" };
            request.AddressesToValidate[0].Address.City = "Deerfield";
            request.AddressesToValidate[0].Address.PostalCode = "53531";
            request.AddressesToValidate[0].Address.CountryCode = "US";
            //
            request.AddressesToValidate[1] = new AddressToValidate();
            request.AddressesToValidate[1].AddressId = "WD";
            request.AddressesToValidate[1].Address = new Address();
            request.AddressesToValidate[1].Address.StreetLines = new String[1] { "2830 Progress Rd" };
            request.AddressesToValidate[1].Address.PostalCode = "53716";
            request.AddressesToValidate[1].CompanyName = "Wingra Direct";

出站 SOAP 请求(使用 Fiddler 获取)。请注意缺少的选项:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Body>
        <AddressValidationRequest xmlns="http://fedex.com/ws/addressvalidation/v2">
            <WebAuthenticationDetail>
                <UserCredential>
                    <Key>XXX-KEY-XXX</Key>
                    <Password>XXX-PWD-XXX</Password>
                </UserCredential>
            </WebAuthenticationDetail>
            <ClientDetail>
                <AccountNumber>XXX-ACCT#-XXX</AccountNumber>
                <MeterNumber>XXX-MTR#-XXX</MeterNumber>
            </ClientDetail>
            <TransactionDetail>
                <CustomerTransactionId>***Address Validation v2 Request using VC#***</CustomerTransactionId>
            </TransactionDetail>
            <Version>
                <ServiceId>aval</ServiceId>
                <Major>2</Major>
                <Intermediate>0</Intermediate>
                <Minor>0</Minor>
            </Version>
            <RequestTimestamp>2010-08-26T16:40:13.2026134-05:00</RequestTimestamp>
            <Options>
                <CheckResidentialStatus>true</CheckResidentialStatus>
                <MaximumNumberOfMatches>5</MaximumNumberOfMatches>
            </Options>
            <AddressesToValidate>
                <AddressId>Kimmel</AddressId>
                <Address>
                    <StreetLines>425 Morningside Dr</StreetLines>
                    <City>Deerfield</City>
                    <PostalCode>53531</PostalCode>
                    <CountryCode>US</CountryCode>
                    <Residential>true</Residential>
                </Address>
            </AddressesToValidate>
            <AddressesToValidate>
                <AddressId>WD</AddressId>
                <CompanyName>Wingra Direct</CompanyName>
                <Address>
                    <StreetLines>2830 Progress Rd</StreetLines>
                    <PostalCode>53716</PostalCode>
                </Address>
            </AddressesToValidate>
        </AddressValidationRequest>
    </soap:Body>
</soap:Envelope>

我得到的回复是:

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <env:Header xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"/>
    <soapenv:Body>
        <v2:AddressValidationReply xmlns:v2="http://fedex.com/ws/addressvalidation/v2">
            <v2:HighestSeverity>SUCCESS</v2:HighestSeverity>
            <v2:Notifications>
                <v2:Severity>SUCCESS</v2:Severity>
                <v2:Source>wsi</v2:Source>
            </v2:Notifications>
            <v2:TransactionDetail xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
                <v2:CustomerTransactionId>***Address Validation v2 Request using VC#***</v2:CustomerTransactionId>
            </v2:TransactionDetail>
            <v2:Version xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
                <v2:ServiceId>aval</v2:ServiceId>
                <v2:Major>2</v2:Major>
                <v2:Intermediate>0</v2:Intermediate>
                <v2:Minor>0</v2:Minor>
            </v2:Version>
            <v2:ReplyTimestamp>2010-08-26T21:40:14.140Z</v2:ReplyTimestamp>
            <v2:AddressResults>
                <v2:AddressId>Kimmel</v2:AddressId>
                <v2:ProposedAddressDetails>
                    <v2:Score>93</v2:Score>
                    <v2:Changes>MODIFIED_TO_ACHIEVE_MATCH</v2:Changes>
                    <v2:ResidentialStatus>UNAVAILABLE</v2:ResidentialStatus>
                    <v2:DeliveryPointValidation>CONFIRMED</v2:DeliveryPointValidation>
                    <v2:Address>
                        <v2:StreetLines>425 Morningside Dr</v2:StreetLines>
                        <v2:City>Deerfield</v2:City>
                        <v2:StateOrProvinceCode>WI</v2:StateOrProvinceCode>
                        <v2:PostalCode>53531-9492</v2:PostalCode>
                        <v2:CountryCode>US</v2:CountryCode>
                    </v2:Address>
                    <v2:RemovedNonAddressData/>
                </v2:ProposedAddressDetails>
            </v2:AddressResults>
            <v2:AddressResults>
                <v2:AddressId>WD</v2:AddressId>
                <v2:ProposedAddressDetails>
                    <v2:Score>93</v2:Score>
                    <v2:Changes>MODIFIED_TO_ACHIEVE_MATCH</v2:Changes>
                    <v2:ResidentialStatus>UNAVAILABLE</v2:ResidentialStatus>
                    <v2:DeliveryPointValidation>CONFIRMED</v2:DeliveryPointValidation>
                    <v2:CompanyName>Wingra Direct</v2:CompanyName>
                    <v2:Address>
                        <v2:StreetLines>2830 Progress Rd</v2:StreetLines>
                        <v2:City>Madison</v2:City>
                        <v2:StateOrProvinceCode>WI</v2:StateOrProvinceCode>
                        <v2:PostalCode>53716-3338</v2:PostalCode>
                        <v2:CountryCode>US</v2:CountryCode>
                    </v2:Address>
                    <v2:RemovedNonAddressData/>
                </v2:ProposedAddressDetails>
            </v2:AddressResults>
        </v2:AddressValidationReply>
    </soapenv:Body>
</soapenv:Envelope>

I'm trying to get the sample FedEx Address Verification application to work in C#. After contacting my FedEx technical contact and having him activate Address Verification on my test account (apparently it is considered an advanced service that requires additional permissions) I was able to compile and run the example application.

However, I wasn't getting quite the results I expected given the settings...

request.Options.ConvertToUpperCase = true;
request.Options.CheckResidentialStatus = true;

Based on these flags, I expected to have the address come back in upper case, and to be able to check the Residential or ResidentialStatus properties to determine commercial vs residential. Neither were occuring.

So I installed Fiddler to see the exact SOAP exchange that was taking place and found that the outbound Options tag was not populating except for one property, MaximumNumberOfMatches.

Is there something I should check for in the Reference.cs file that is created by Visual Studio? I didn't see anything out of the norm, but something is happening that is preventing the serialization of some of the properties.

--Edit--

Updated my code as per the suggestion below. Unfortunately, it still only populates 2 of the options parameters. I've included the C# settings code and the outbound/inbound SOAP request below. Can anyone think of a reason the rest of the options are not being sent in the SOAP request?

AddressValidationRequest request = new AddressValidationRequest();
            //
            request.WebAuthenticationDetail = new WebAuthenticationDetail();
            request.WebAuthenticationDetail.UserCredential = new WebAuthenticationCredential();
            request.WebAuthenticationDetail.UserCredential.Key = "XXX-KEY-XXX"; // Replace "XXX" with the Key
            request.WebAuthenticationDetail.UserCredential.Password = "XXX-PWD-XXX"; // Replace "XXX" with the Password
            //
            request.ClientDetail = new ClientDetail();
            request.ClientDetail.AccountNumber = "XXX-ACCT#-XXX"; // Replace "XXX" with client's account number
            request.ClientDetail.MeterNumber = "XXX-MTR#-XXX"; // Replace "XXX" with client's meter number
            //
            request.TransactionDetail = new TransactionDetail();
            request.TransactionDetail.CustomerTransactionId = "***Address Validation v2 Request using VC#***"; // This is just an echo back 
            //
            request.Version = new VersionId(); // Creates the Version element with all child elements populated
            //
            request.RequestTimestamp = DateTime.Now;
            //
            request.Options = new AddressValidationOptions();
            request.Options.CheckResidentialStatus = true;
            request.Options.CheckResidentialStatusSpecified = true;
            request.Options.VerifyAddresses = true;
            request.Options.MaximumNumberOfMatches = "5";
            request.Options.StreetAccuracy = AddressValidationAccuracyType.MEDIUM;
            request.Options.DirectionalAccuracy = AddressValidationAccuracyType.MEDIUM;
            request.Options.CompanyNameAccuracy = AddressValidationAccuracyType.MEDIUM;
            request.Options.ConvertToUpperCase = true;
            request.Options.RecognizeAlternateCityNames = true;
            request.Options.ReturnParsedElements = true;
            //
            request.AddressesToValidate = new AddressToValidate[2];
            request.AddressesToValidate[0] = new AddressToValidate();
            request.AddressesToValidate[0].AddressId = "Kimmel";
            request.AddressesToValidate[0].Address = new Address();
            request.AddressesToValidate[0].Address.StreetLines = new String[1] { "425 Morningside Dr" };
            request.AddressesToValidate[0].Address.City = "Deerfield";
            request.AddressesToValidate[0].Address.PostalCode = "53531";
            request.AddressesToValidate[0].Address.CountryCode = "US";
            //
            request.AddressesToValidate[1] = new AddressToValidate();
            request.AddressesToValidate[1].AddressId = "WD";
            request.AddressesToValidate[1].Address = new Address();
            request.AddressesToValidate[1].Address.StreetLines = new String[1] { "2830 Progress Rd" };
            request.AddressesToValidate[1].Address.PostalCode = "53716";
            request.AddressesToValidate[1].CompanyName = "Wingra Direct";

The outbound SOAP Request (obtained using Fiddler). Note the missing options:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Body>
        <AddressValidationRequest xmlns="http://fedex.com/ws/addressvalidation/v2">
            <WebAuthenticationDetail>
                <UserCredential>
                    <Key>XXX-KEY-XXX</Key>
                    <Password>XXX-PWD-XXX</Password>
                </UserCredential>
            </WebAuthenticationDetail>
            <ClientDetail>
                <AccountNumber>XXX-ACCT#-XXX</AccountNumber>
                <MeterNumber>XXX-MTR#-XXX</MeterNumber>
            </ClientDetail>
            <TransactionDetail>
                <CustomerTransactionId>***Address Validation v2 Request using VC#***</CustomerTransactionId>
            </TransactionDetail>
            <Version>
                <ServiceId>aval</ServiceId>
                <Major>2</Major>
                <Intermediate>0</Intermediate>
                <Minor>0</Minor>
            </Version>
            <RequestTimestamp>2010-08-26T16:40:13.2026134-05:00</RequestTimestamp>
            <Options>
                <CheckResidentialStatus>true</CheckResidentialStatus>
                <MaximumNumberOfMatches>5</MaximumNumberOfMatches>
            </Options>
            <AddressesToValidate>
                <AddressId>Kimmel</AddressId>
                <Address>
                    <StreetLines>425 Morningside Dr</StreetLines>
                    <City>Deerfield</City>
                    <PostalCode>53531</PostalCode>
                    <CountryCode>US</CountryCode>
                    <Residential>true</Residential>
                </Address>
            </AddressesToValidate>
            <AddressesToValidate>
                <AddressId>WD</AddressId>
                <CompanyName>Wingra Direct</CompanyName>
                <Address>
                    <StreetLines>2830 Progress Rd</StreetLines>
                    <PostalCode>53716</PostalCode>
                </Address>
            </AddressesToValidate>
        </AddressValidationRequest>
    </soap:Body>
</soap:Envelope>

The response I get back is:

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <env:Header xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"/>
    <soapenv:Body>
        <v2:AddressValidationReply xmlns:v2="http://fedex.com/ws/addressvalidation/v2">
            <v2:HighestSeverity>SUCCESS</v2:HighestSeverity>
            <v2:Notifications>
                <v2:Severity>SUCCESS</v2:Severity>
                <v2:Source>wsi</v2:Source>
            </v2:Notifications>
            <v2:TransactionDetail xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
                <v2:CustomerTransactionId>***Address Validation v2 Request using VC#***</v2:CustomerTransactionId>
            </v2:TransactionDetail>
            <v2:Version xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
                <v2:ServiceId>aval</v2:ServiceId>
                <v2:Major>2</v2:Major>
                <v2:Intermediate>0</v2:Intermediate>
                <v2:Minor>0</v2:Minor>
            </v2:Version>
            <v2:ReplyTimestamp>2010-08-26T21:40:14.140Z</v2:ReplyTimestamp>
            <v2:AddressResults>
                <v2:AddressId>Kimmel</v2:AddressId>
                <v2:ProposedAddressDetails>
                    <v2:Score>93</v2:Score>
                    <v2:Changes>MODIFIED_TO_ACHIEVE_MATCH</v2:Changes>
                    <v2:ResidentialStatus>UNAVAILABLE</v2:ResidentialStatus>
                    <v2:DeliveryPointValidation>CONFIRMED</v2:DeliveryPointValidation>
                    <v2:Address>
                        <v2:StreetLines>425 Morningside Dr</v2:StreetLines>
                        <v2:City>Deerfield</v2:City>
                        <v2:StateOrProvinceCode>WI</v2:StateOrProvinceCode>
                        <v2:PostalCode>53531-9492</v2:PostalCode>
                        <v2:CountryCode>US</v2:CountryCode>
                    </v2:Address>
                    <v2:RemovedNonAddressData/>
                </v2:ProposedAddressDetails>
            </v2:AddressResults>
            <v2:AddressResults>
                <v2:AddressId>WD</v2:AddressId>
                <v2:ProposedAddressDetails>
                    <v2:Score>93</v2:Score>
                    <v2:Changes>MODIFIED_TO_ACHIEVE_MATCH</v2:Changes>
                    <v2:ResidentialStatus>UNAVAILABLE</v2:ResidentialStatus>
                    <v2:DeliveryPointValidation>CONFIRMED</v2:DeliveryPointValidation>
                    <v2:CompanyName>Wingra Direct</v2:CompanyName>
                    <v2:Address>
                        <v2:StreetLines>2830 Progress Rd</v2:StreetLines>
                        <v2:City>Madison</v2:City>
                        <v2:StateOrProvinceCode>WI</v2:StateOrProvinceCode>
                        <v2:PostalCode>53716-3338</v2:PostalCode>
                        <v2:CountryCode>US</v2:CountryCode>
                    </v2:Address>
                    <v2:RemovedNonAddressData/>
                </v2:ProposedAddressDetails>
            </v2:AddressResults>
        </v2:AddressValidationReply>
    </soapenv:Body>
</soapenv:Envelope>

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

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

发布评论

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

评论(3

耶耶耶 2024-09-21 19:22:38

看起来 on option 会被忽略,除非您也将 optionSpecified 标志设置为 true。

这是我有效的新选项代码 - 关键是您需要为您想要的每个选项添加 Options.(property)specified = true :

    request.Options = New AddressValidationOptions()
    request.Options.CheckResidentialStatus = True
    request.Options.CheckResidentialStatusSpecified = True
    request.Options.VerifyAddresses = True
    request.Options.VerifyAddressesSpecified = True
    request.Options.MaximumNumberOfMatches = 5
    request.Options.StreetAccuracy = AddressValidationAccuracyType.MEDIUM
    request.Options.DirectionalAccuracy = AddressValidationAccuracyType.MEDIUM
    request.Options.CompanyNameAccuracy = AddressValidationAccuracyType.MEDIUM
    request.Options.ConvertToUpperCase = True
    request.Options.ConvertToUpperCaseSpecified = True
    request.Options.RecognizeAlternateCityNames = True
    request.Options.RecognizeAlternateCityNamesSpecified = True
    request.Options.ReturnParsedElements = True
    request.Options.ReturnParsedElementsSpecified = True

It appears that on option is ignored unless you also set the optionSpecified flag to true also.

Here is my new options code that works - the key being that you need to add the Options.(property)specified = true for each one you want:

    request.Options = New AddressValidationOptions()
    request.Options.CheckResidentialStatus = True
    request.Options.CheckResidentialStatusSpecified = True
    request.Options.VerifyAddresses = True
    request.Options.VerifyAddressesSpecified = True
    request.Options.MaximumNumberOfMatches = 5
    request.Options.StreetAccuracy = AddressValidationAccuracyType.MEDIUM
    request.Options.DirectionalAccuracy = AddressValidationAccuracyType.MEDIUM
    request.Options.CompanyNameAccuracy = AddressValidationAccuracyType.MEDIUM
    request.Options.ConvertToUpperCase = True
    request.Options.ConvertToUpperCaseSpecified = True
    request.Options.RecognizeAlternateCityNames = True
    request.Options.RecognizeAlternateCityNamesSpecified = True
    request.Options.ReturnParsedElements = True
    request.Options.ReturnParsedElementsSpecified = True
薄凉少年不暖心 2024-09-21 19:22:38

我无法让 API 正常工作,因此我最终手动编写了 SOAP 请求和响应处理的代码。除了 API 没有正确设置所有标志之外,我还发现 FedEx DEV 服务器没有返回住宅状态,无论选项是什么(由我们的 FedEx Web 服务联系人确认)。当我们获得对生产服务器的访问权限时,新代码就像魅力一样发挥作用。

I was unable to get the API working so I ended up manually coding the handling of SOAP requests and responses. Aside from the API not properly setting all the flags, I also found out that the FedEx DEV server was not returning the Residential Status, regardless of what the options were (confirmed by our FedEx Web Services contact). When we gained access to the production servers the new code worked like a charm.

欢烬 2024-09-21 19:22:38

这是联邦快递技术支持的另一个答案:

“测试中无法使用地址验证 API
环境”。

所以我不确定你是如何“激活”测试帐户以进行地址验证的。据说 FedEx 系统使用 USPS 生产地址验证系统,这就是为什么无法从 FedEx 测试环境访问它的原因。

不知道如果我 100% 相信这一点,但我知道我正在使用有效凭据访问 FedEx 测试服务器并收到“身份验证失败”响应。

Here's another answer from FedEx tech support:

"The address verification API is not available from the test
environment".

So I'm not sure how you got your test account "activated" for address verification. Supposedly the FedEx system uses the USPS production address verification system which is why it's not accessible from the FedEx test environment.

I don't know if I believe this 100%, but I know that I'm hitting the FedEx test server with valid credentials and getting a "Authentication Failed" response.

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