FedEx Web Service用于打印多个运输标签

时间:2010-06-04 21:35:48

标签: fedex

我正在尝试连接到FedEx shipping webservice v8。

当我只有一个RequestedPackageLineItems集时,一切正常。当我添加两个项目时,我收到以下错误。

“包裹数量无效或包裹序列号无效。”

我的代码如下

ProcessShipmentRequest request = CreatePendingShipmentRequest();
ShipService service = new ShipService();
ProcessShipmentReply reply = service.processShipment(request);
...

private static ProcessShipmentRequest CreatePendingShipmentRequest()
{
    ProcessShipmentRequest request = new ProcessShipmentRequest();

    request.WebAuthenticationDetail = new WebAuthenticationDetail();
    request.WebAuthenticationDetail.UserCredential = new WebAuthenticationCredential();
    request.WebAuthenticationDetail.UserCredential.Key = "XXX"; 
    request.WebAuthenticationDetail.UserCredential.Password = "XXX";            
    request.ClientDetail = new ClientDetail();
    request.ClientDetail.AccountNumber = "XXX";
    request.ClientDetail.MeterNumber = "XXX"; 

    request.TransactionDetail = new TransactionDetail();
    request.TransactionDetail.CustomerTransactionId = "*** Ground Domestic Shipping Request v8 using C# ***";
    request.Version = new VersionId();

    //Inside this method I set request.RequestedShipment.PackageCount = "2";
    SetShipmentDetails(request);
    SetPackageLineItems(request);

    return request;
}

private static void SetPackageLineItems(ProcessShipmentRequest request)
{                   
    request.RequestedShipment.RequestedPackageLineItems = new RequestedPackageLineItem[2];
    request.RequestedShipment.RequestedPackageLineItems[0] = new RequestedPackageLineItem();
    request.RequestedShipment.RequestedPackageLineItems[0].SequenceNumber = "1";
    request.RequestedShipment.RequestedPackageLineItems[0].Weight = new Weight();
    request.RequestedShipment.RequestedPackageLineItems[0].Weight.Value = 50.0M;
    request.RequestedShipment.RequestedPackageLineItems[0].Weight.Units = WeightUnits.LB;
    request.RequestedShipment.RequestedPackageLineItems[0].ItemDescription = "Item";
    request.RequestedShipment.RequestedPackageLineItems[0].Dimensions = new Dimensions();
    request.RequestedShipment.RequestedPackageLineItems[0].Dimensions.Length = "108";
    request.RequestedShipment.RequestedPackageLineItems[0].Dimensions.Width = "5";
    request.RequestedShipment.RequestedPackageLineItems[0].Dimensions.Height = "5";
    request.RequestedShipment.RequestedPackageLineItems[0].Dimensions.Units = LinearUnits.IN;

    request.RequestedShipment.RequestedPackageLineItems[0].CustomerReferences = new CustomerReference[3];
    request.RequestedShipment.RequestedPackageLineItems[0].CustomerReferences[0] = new CustomerReference();
    request.RequestedShipment.RequestedPackageLineItems[0].CustomerReferences[0].CustomerReferenceType = CustomerReferenceType.CUSTOMER_REFERENCE;
    request.RequestedShipment.RequestedPackageLineItems[0].CustomerReferences[0].Value = "[LOT NUMBER]";
    request.RequestedShipment.RequestedPackageLineItems[0].CustomerReferences[1] = new CustomerReference();
    request.RequestedShipment.RequestedPackageLineItems[0].CustomerReferences[1].CustomerReferenceType = CustomerReferenceType.INVOICE_NUMBER;
    request.RequestedShipment.RequestedPackageLineItems[0].CustomerReferences[1].Value = "45646";
    request.RequestedShipment.RequestedPackageLineItems[0].CustomerReferences[2] = new CustomerReference();
    request.RequestedShipment.RequestedPackageLineItems[0].CustomerReferences[2].CustomerReferenceType = CustomerReferenceType.P_O_NUMBER;
    request.RequestedShipment.RequestedPackageLineItems[0].CustomerReferences[2].Value = "456446";

    request.RequestedShipment.RequestedPackageLineItems[1] = new RequestedPackageLineItem();
    request.RequestedShipment.RequestedPackageLineItems[1].SequenceNumber = "2";
    request.RequestedShipment.RequestedPackageLineItems[1].Weight = new Weight();
    request.RequestedShipment.RequestedPackageLineItems[1].Weight.Value = 50.0M;
    request.RequestedShipment.RequestedPackageLineItems[1].Weight.Units = WeightUnits.LB;
    request.RequestedShipment.RequestedPackageLineItems[1].ItemDescription = "Item";
    ....
}

2 个答案:

答案 0 :(得分:3)

了解如何执行此操作。

为了将多个运输标签合并为一个pdf,过程如下:

  1. 创建请求
  2. 填写送货信息
  3. 发布并回复。
  4. 保存重播和字节数组以及MasterShippingID
  5. 创建新请求并为其分配主要运送ID。
  6. 增加了运输重量和尺寸
  7. 发布并获得回复
  8. 使用其他
  9. 保存字节数组
  10. 继续,直到生成所有货件(每个主货运ID最多200个)
  11. 将从FedEx返回的所有pdf合并为一个pdf。
  12. 做一个快乐的舞蹈。

答案 1 :(得分:0)

一种更简单的方法(虽然有成本)是Shiprush SDK。它允许你构建一个XML块,让ShipRush用fedex(或任何人)做所有有趣的事情。

他们也支持他们的工具。