OrderFulfillment リクエスト用の AmazonEnvelope を構築し、そのエンベロープのコンテンツを SubmitFeedRequest に追加し、MarketplaceWebServiceClient をセットアップした後 (すべてエラーなし)、フィードを送信しようとして停止しました。例外メッセージの正確な文言は次のとおりです。
String reference not set to an instance of a String.
Parameter name: s
これは、WebServiceClient がデータに署名しようとしたときに呼び出される GetBytes というシステム レベルのメソッドを参照しています。完全なスタック トレース:
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"
フィードに必要なデータが欠落している可能性がありますか? SubmitFeed リクエストに至るまでの完全なコードは次のとおりです。
/** 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);
すべてのテキストで申し訳ありませんが、このエラーはあまり説明的ではありません...あらゆるヘルプが大歓迎です!