1

在为 OrderFulfillment 请求构建 AmazonEnvelope、将该信封的内容添加到 SubmitFeedRequest 并设置 MarketplaceWebServiceClient 之后 - 所有这些都没有错误 - 我停止尝试提交提要。异常消息的确切措辞是:

String reference not set to an instance of a String.
Parameter name: s

这引用了一个称为 GetBytes 的系统级方法,当 WebServiceClient 尝试对数据进行签名时会调用该方法。完整的堆栈跟踪:

at System.Text.Encoding.GetBytes(String s)
at MarketplaceWebService.MarketplaceWebServiceClient.Sign(String data, String key, KeyedHashAlgorithm algorithm)
at MarketplaceWebService.MarketplaceWebServiceClient.SignParameters(IDictionary`2 parameters, String key)
at MarketplaceWebService.MarketplaceWebServiceClient.AddRequiredParameters(IDictionary`2 parameters)
at MarketplaceWebService.MarketplaceWebServiceClient.InvokeT,K(IDictionary`2 parameters, K clazz)
at MarketplaceWebService.MarketplaceWebServiceClient.SubmitFeed(SubmitFeedRequest request)
at ProcessTracking.ProcessTracking.Execute(Int32 companyId) in c:\ProcessTracking\ProcessTracking\ProcessTracking.cs:line 281"

也许我错过了提要所需的数据?以下是提交提交请求的完整代码:

/** build the feed **/

var envelope = new AmazonEnvelope
{
    Header = new Header
    {
        DocumentVersion = "1.01",
        MerchantIdentifier = ConfigurationManager.AppSettings["AmazonMerchantId"]
    },
    MarketplaceName = ConfigurationManager.AppSettings["AmazonMarketplaceId"],
    EffectiveDate = DateTime.Now,
    EffectiveDateSpecified = true,
    MessageType = AmazonEnvelopeMessageType.OrderFulfillment
};

envelope.Message = new AmazonEnvelopeMessage[1];
envelope.Message[0] = new AmazonEnvelopeMessage
{
    MessageID = order.AltPaymentId,
    OperationType = AmazonEnvelopeMessageOperationType.Update,
    OperationTypeSpecified = true
};

var products = new OrderFulfillmentItem[order.OrderLineItems.Count];
var count = 0;
foreach (var product in order.OrderLineItems)
{
    foreach (var option in product.OrderLineItemOptions)
    {
        var qty = (option.PriceAdder == 0) ? product.Quantity.ToString() : "1";
        products[count] = new OrderFulfillmentItem
        {
            ItemElementName = ItemChoiceType3.MerchantOrderItemID,
            MerchantFulfillmentItemID = option.ProductAttributeId.ToString(),
            Quantity = qty
        };

        count++;
    }
}

envelope.Message[0].Item = new OrderFulfillment
{
    ItemElementName = ItemChoiceType2.AmazonOrderID,
    MerchantFulfillmentID = order.AltPaymentId,
    FulfillmentDate = DateTime.Now,
    FulfillmentData = new OrderFulfillmentFulfillmentData
    {
        ShippingMethod = order.ShippingType.Name,
        ShipperTrackingNumber = order.TrackingNumber,
        Item = order.Shipper == "FedEx" ? CarrierCode.FedEx : CarrierCode.UPS,
    },
    Item1 = products
};

var myserializer = new XmlSerializer(typeof(AmazonEnvelope));
var mywriter = new StreamWriter(Environment.CurrentDirectory + "\\AmazonOrders\\Details-" + order.ID.ToString() + ".xml");
myserializer.Serialize(mywriter, envelope);
mywriter.Close();


/** submit the feed **/
var request = new SubmitFeedRequest
{
    Merchant = ConfigurationManager.AppSettings["AmazonMerchantId"],
    Marketplace = ConfigurationManager.AppSettings["AmazonMarketplaceId"],
    FeedType = "_POST_ORDER_FULFILLMENT_DATA_",
    FeedContent = File.Open(Environment.CurrentDirectory + "\\AmazonOrders\\Details-" + order.ID.ToString() + ".xml", FileMode.Open, FileAccess.Read)
};

request.ContentMD5 = MarketplaceWebServiceClient.CalculateContentMD5(request.FeedContent);

var serviceConfig = new MarketplaceWebServiceConfig
{
    serviceURL = "https://mws.amazonservices.com",
    marketplaceId = ConfigurationManager.AppSettings["AmazonMarketplaceId"],
    accessKey = ConfigurationManager.AppSettings["AmazonAWSkeyId"],
    secretKey = ConfigurationManager.AppSettings["AmazonAWSsecretId"],
};

var serviceFeed =
    new MarketplaceWebServiceClient(
        ConfigurationManager.AppSettings["AmazonAWSkeyId"],
        ConfigurationManager.AppSettings["AmazonAWSsecretId"],
        "ProcessTracking",
        "2.0",
        serviceConfig
    );

var response = serviceFeed.SubmitFeed(request);

对不起所有的文字,但这个错误不是很具有描述性......任何和所有的帮助都非常感谢!

4

0 回答 0