使用Ebay SDK API:internationalShippingOptions.ShipToLocation.Add(“Worldwide”);原因:“对象引用未设置为对象的实例”

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用Ebay SDK API:internationalShippingOptions.ShipToLocation.Add(“Worldwide”);原因:“对象引用未设置为对象的实例”相关的知识,希望对你有一定的参考价值。

我的目标是让这个列表说“免费国际航运”。试图设置国际选项,它说我需要设置ShipToLocation我尝试了下面这一行:

internationalShippingOptions.ShipToLocation.Add("Worldwide");

但是当程序遇到它时我得到这个错误:

"Object reference not set to an instance of an object"

如果你想看到完整的方法:

    static ShippingDetailsType BuildShippingDetails()
    {

        ShippingDetailsType sd = new ShippingDetailsType();
        sd.ApplyShippingDiscount = false;
        sd.ShippingType = ShippingTypeCodeType.Flat;

        AmountType amount = new AmountType();
        amount.Value = 0;
        amount.currencyID = CurrencyCodeType.USD;            

        ShippingServiceOptionsTypeCollection shippingOptions = new ShippingServiceOptionsTypeCollection();

        ShippingServiceOptionsType domesticShippingOptions = new ShippingServiceOptionsType();
        domesticShippingOptions.ShippingService = ShippingServiceCodeType.EconomyShippingFromOutsideUS.ToString();
        domesticShippingOptions.FreeShipping = true;
        domesticShippingOptions.ShippingServiceCost = amount;
        domesticShippingOptions.ShippingServicePriority = 1;
        shippingOptions.Add(domesticShippingOptions);

        ShippingServiceOptionsType internationalShippingOptions = new ShippingServiceOptionsType();
        InternationalShippingServiceOptionsType internationalShippingOptions = new InternationalShippingServiceOptionsType();
        internationalShippingOptions.ShippingService = ShippingServiceCodeType.StandardInternational.ToString();
        internationalShippingOptions.ShipToLocation.Add("Worldwide");
        internationalShippingOptions.FreeShipping = true;

        sd.InternationalShippingServiceOption = new InternationalShippingServiceOptionsTypeCollection(new InternationalShippingServiceOptionsType[] { internationalShippingOptions });
        sd.ShippingServiceOptions = shippingOptions;

        return sd;
    }
答案

这是让它说“Free Standard Intl Shipping”的代码。首先在沙箱中显示“免费标准送货”,但如果您更改沙箱中的送货目的地,则会显示“免费标准国际送货”。

    static ShippingDetailsType BuildShippingDetails()
    {
        // Shipping details
        ShippingDetailsType sd = new ShippingDetailsType();

        sd.ApplyShippingDiscount = true;
        sd.PaymentInstructions = "eBay .Net SDK test instruction.";
        sd.ShippingRateType = ShippingRateTypeCodeType.StandardList;

        // Shipping type and shipping service options
        //adding international shipping
        InternationalShippingServiceOptionsType internationalShipping1 = new InternationalShippingServiceOptionsType();
        internationalShipping1.ShippingService = ShippingServiceCodeType.StandardInternational.ToString();
        internationalShipping1.ShippingServiceCost = new AmountType { Value = 0, currencyID = CurrencyCodeType.USD };
        internationalShipping1.ShippingServicePriority = 1;
        internationalShipping1.ShipToLocation = new StringCollection(new[] { "Worldwide" });
        sd.ShippingServiceUsed = ShippingServiceCodeType.StandardInternational.ToString();
        sd.InternationalShippingServiceOption = new InternationalShippingServiceOptionsTypeCollection(new[] { internationalShipping1 });

        //adding domestic shipping
        ShippingServiceOptionsType domesticShipping1 = new ShippingServiceOptionsType();
        domesticShipping1.ShippingService = ShippingServiceCodeType.ShippingMethodStandard.ToString();
        domesticShipping1.ShippingServiceCost = new AmountType { Value = 0, currencyID = CurrencyCodeType.USD };
        domesticShipping1.ShippingInsuranceCost = new AmountType { Value = 0, currencyID = CurrencyCodeType.USD };
        domesticShipping1.ShippingServicePriority = 4;
        domesticShipping1.LocalPickup = true;
        domesticShipping1.FreeShipping = true;
        sd.ShippingServiceOptions = new ShippingServiceOptionsTypeCollection(new[] { domesticShipping1 });
        sd.ShippingType = ShippingTypeCodeType.Flat;

        return sd;

要调用方法:

 item.ShippingDetails = BuildShippingDetails();

以上是关于使用Ebay SDK API:internationalShippingOptions.ShipToLocation.Add(“Worldwide”);原因:“对象引用未设置为对象的实例”的主要内容,如果未能解决你的问题,请参考以下文章

ebay 如何获取用户token

使用eBay API基本步骤介绍

如何通过 eBay API 获取 PayPal TransactionID

如何使用 python xml.etree.ElementTree 解析 eBay API 响应?

我们应该将哪个 PayPal API 用于市场(ebay 模型)?

接收 eBay SOAP 通知消息