开发者

FedEx Webservice for printing Multiple shipping labels

I am trying to connect to the FedEx shipping webservice v8.

Everything works fine when I only have one RequestedPackageLineItems set. When I add two items I get the following error.

"Invalid package count or invalid package sequence number."

My Code is as follows

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 = L开发者_C百科inearUnits.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";
    ....
}


Found out how to do this.

In order to get multiple shipping labels into one pdf the process is as follows.

  1. Create a request
  2. Fill in the shipping info
  3. Post and get a reply.
  4. Save that replay and the byte array and MasterShippingID
  5. Create a new request and assign the master shipping id to it.
  6. Added shipping weight and dimensions
  7. Post and get reply
  8. Save byte array with the other
  9. Continue until all shipments are generated (max 200 per master shipping id)
  10. Merge all the pdfs returned from FedEx into one pdf.
  11. Do a happy dance.


A simpler approach, (though there is a cost) is the Shiprush SDK. It lets you build a single XML block and let ShipRush do all the funny stuff with fedex (or whoever).

They also support their tool.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜