Fedex地址验证Web参考问题

时间:2010-08-19 21:42:56

标签: c# web-services asmx fedex

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

然而,鉴于设置,我没有得到我预期的结果......

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

基于这些标志,我希望地址以大写字母回复,并且能够检查住宅或住宅状态属性以确定商业与住宅。两者都没有发生。

所以我安装了Fiddler来查看正在发生的确切SOAP交换,发现除了一个属性MaximumNumberOfMatches外,没有填充出站的Options标签。

我应该在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>

3 个答案:

答案 0 :(得分:2)

除非您还将optionSpecified标志设置为true,否则将忽略on选项。

这是我的新选项代码可行 - 关键是您需要为每个选项添加选项。(属性)指定= 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

答案 1 :(得分:2)

以下是FedEx技术支持的另一个答案:

  

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

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

我不知道我是否相信这100%,但我知道我正在使用有效凭据进入FedEx测试服务器并获得“身份验证失败”响应。

答案 2 :(得分:0)

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