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

问题描述 投票:0回答:1

我的目标是让这个列表说“免费国际航运”。试图设置国际选项,它说我需要设置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;
    }
c# soap sdk ebay
1个回答
0
投票

这是让它说“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();
© www.soinside.com 2019 - 2024. All rights reserved.