locked
How to display FedEx Shipping Rates in an HTML Table RRS feed

  • Question

  • User540310021 posted

    Hi,

    I have downloaded the wsdl file as well as the sample c# code provided by FedEx. I have all the keys with me UserKey, UserPassword, AccountNumber and MeterNumber. The sample code works like a charm showing the shipping rates.

    The sample c# code is a Console C# app, I am fairly new to using Web Services in .NET. Can anybody please guide me how to go about with this. How can I use the sample c# code provided by FedEx within a ASP.NET WebForm Page with a button. When a user clicks that button then it should show the respected Shipping Rates in an HTML Table.

    Thanks in advance.

    Thursday, November 7, 2013 2:26 AM

Answers

  • User-741098373 posted

    Took sometime to reply, as I was writing the code.

    Here's the full project : https://www.dropbox.com/s/24oa4za3ma6sx8g/WebApplication2.rar

    Here's your whole source

    ASPX Page:

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1.Default" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:ScriptManager ID="ScriptManager1" runat="server">
            </asp:ScriptManager>
    
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                    <asp:ListBox ID="ListBox1" runat="server" AppendDataBoundItems="true"></asp:ListBox>
                    <br />
                    <asp:Button ID="btnGetRate" runat="server" Text="Get Rate"
                        onclick="btnGetRate_Click" />
                    <br />
                    <asp:Table ID="Table1" runat="server">
                    </asp:Table>
                </ContentTemplate>
            </asp:UpdatePanel>
        </div>
        </form>
    </body>
    </html>

    I'm using the listbox to show any error details.

    Code-Behind:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.Services.Protocols;
    using WebApplication1.RateServiceReference;
    
    namespace WebApplication1
    {
        public partial class Default : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
    
            }
    
            protected void btnGetRate_Click(object sender, EventArgs e)
            {
                RateRequest request = CreateRateRequest();
                //
                RateService service = new RateService();
    
                try
                {
                    // Call the web service passing in a RateRequest and returning a RateReply
                    RateReply reply = service.getRates(request);
    
                    if (reply.HighestSeverity == NotificationSeverityType.SUCCESS || reply.HighestSeverity == NotificationSeverityType.NOTE || reply.HighestSeverity == NotificationSeverityType.WARNING)
                    {
                        ShowRateReply(reply);
                    }
                    ShowNotifications(reply);
                }
                catch (SoapException ex)
                {
                    ListBox1.Items.Add(ex.Detail.InnerText);
                }
                catch (Exception ex)
                {
                    ListBox1.Items.Add(ex.Message);
                }
            }
    
            private RateRequest CreateRateRequest()
            {
                // Build a RateRequest
                RateRequest request = new RateRequest();
                //
                request.WebAuthenticationDetail = new WebAuthenticationDetail();
                request.WebAuthenticationDetail.UserCredential = new WebAuthenticationCredential();
                request.WebAuthenticationDetail.UserCredential.Key = "XXX"; // Replace "XXX" with the Key
                request.WebAuthenticationDetail.UserCredential.Password = "XXX"; // Replace "XXX" with the Password
                
                //
                request.ClientDetail = new ClientDetail();
                request.ClientDetail.AccountNumber = "XXX"; // Replace "XXX" with the client's account number
                request.ClientDetail.MeterNumber = "XXX"; // Replace "XXX" with the client's meter number
                
                //
                request.TransactionDetail = new TransactionDetail();
                request.TransactionDetail.CustomerTransactionId = "***Rate v14 Request using VC#***"; // This is a reference field for the customer.  Any value can be used and will be provided in the response.
                //
                request.Version = new VersionId();
                //
                request.ReturnTransitAndCommit = true;
                request.ReturnTransitAndCommitSpecified = true;
                //
                SetShipmentDetails(request);
                //
                return request;
            }
    
            private void SetShipmentDetails(RateRequest request)
            {
                request.RequestedShipment = new RequestedShipment();
                request.RequestedShipment.ShipTimestamp = DateTime.Now; // Shipping date and time
                request.RequestedShipment.ShipTimestampSpecified = true;
                request.RequestedShipment.DropoffType = DropoffType.REGULAR_PICKUP; //Drop off types are BUSINESS_SERVICE_CENTER, DROP_BOX, REGULAR_PICKUP, REQUEST_COURIER, STATION
                request.RequestedShipment.ServiceType = ServiceType.INTERNATIONAL_PRIORITY; // Service types are STANDARD_OVERNIGHT, PRIORITY_OVERNIGHT, FEDEX_GROUND ...
                request.RequestedShipment.ServiceTypeSpecified = true;
                request.RequestedShipment.PackagingType = PackagingType.YOUR_PACKAGING; // Packaging type FEDEX_BOK, FEDEX_PAK, FEDEX_TUBE, YOUR_PACKAGING, ...
                request.RequestedShipment.PackagingTypeSpecified = true;
                //
                SetOrigin(request);
                //
                SetDestination(request);
                //
                SetPackageLineItems(request);
                //
                request.RequestedShipment.TotalInsuredValue = new Money();
                request.RequestedShipment.TotalInsuredValue.Amount = 100;
                request.RequestedShipment.TotalInsuredValue.Currency = "USD";
                //
                request.RequestedShipment.RateRequestTypes = new RateRequestType[2];
                request.RequestedShipment.RateRequestTypes[0] = RateRequestType.ACCOUNT;
                request.RequestedShipment.RateRequestTypes[1] = RateRequestType.LIST;
                request.RequestedShipment.PackageCount = "2";
            }
    
            private void SetOrigin(RateRequest request)
            {
                request.RequestedShipment.Shipper = new Party();
                request.RequestedShipment.Shipper.Address = new Address();
                request.RequestedShipment.Shipper.Address.StreetLines = new string[1] { "SHIPPER ADDRESS LINE 1" };
                request.RequestedShipment.Shipper.Address.City = "COLLIERVILLE";
                request.RequestedShipment.Shipper.Address.StateOrProvinceCode = "TN";
                request.RequestedShipment.Shipper.Address.PostalCode = "38017";
                request.RequestedShipment.Shipper.Address.CountryCode = "US";
            }
    
            private void SetDestination(RateRequest request)
            {
                request.RequestedShipment.Recipient = new Party();
                request.RequestedShipment.Recipient.Address = new Address();
                request.RequestedShipment.Recipient.Address.StreetLines = new string[1] { "RECIPIENT ADDRESS LINE 1" };
                request.RequestedShipment.Recipient.Address.City = "Montreal";
                request.RequestedShipment.Recipient.Address.StateOrProvinceCode = "PQ";
                request.RequestedShipment.Recipient.Address.PostalCode = "H1E1A1";
                request.RequestedShipment.Recipient.Address.CountryCode = "CA";
            }
    
            private void SetPackageLineItems(RateRequest request)
            {
                request.RequestedShipment.RequestedPackageLineItems = new RequestedPackageLineItem[2];
                request.RequestedShipment.RequestedPackageLineItems[0] = new RequestedPackageLineItem();
                request.RequestedShipment.RequestedPackageLineItems[0].SequenceNumber = "1"; // package sequence number
                request.RequestedShipment.RequestedPackageLineItems[0].GroupPackageCount = "1";
                // package weight
                request.RequestedShipment.RequestedPackageLineItems[0].Weight = new Weight();
                request.RequestedShipment.RequestedPackageLineItems[0].Weight.Units = WeightUnits.LB;
                request.RequestedShipment.RequestedPackageLineItems[0].Weight.UnitsSpecified = true;
                request.RequestedShipment.RequestedPackageLineItems[0].Weight.Value = 15.0M;
                request.RequestedShipment.RequestedPackageLineItems[0].Weight.ValueSpecified = true;
                // package dimensions
                request.RequestedShipment.RequestedPackageLineItems[0].Dimensions = new Dimensions();
                request.RequestedShipment.RequestedPackageLineItems[0].Dimensions.Length = "10";
                request.RequestedShipment.RequestedPackageLineItems[0].Dimensions.Width = "13";
                request.RequestedShipment.RequestedPackageLineItems[0].Dimensions.Height = "4";
                request.RequestedShipment.RequestedPackageLineItems[0].Dimensions.Units = LinearUnits.IN;
                request.RequestedShipment.RequestedPackageLineItems[0].Dimensions.UnitsSpecified = true;
                // insured value
                request.RequestedShipment.RequestedPackageLineItems[0].InsuredValue = new Money();
                request.RequestedShipment.RequestedPackageLineItems[0].InsuredValue.Amount = 100;
                request.RequestedShipment.RequestedPackageLineItems[0].InsuredValue.Currency = "USD";
                //
                request.RequestedShipment.RequestedPackageLineItems[1] = new RequestedPackageLineItem();
                request.RequestedShipment.RequestedPackageLineItems[1].SequenceNumber = "2"; // package sequence number
                request.RequestedShipment.RequestedPackageLineItems[1].GroupPackageCount = "1";
                // package weight
                request.RequestedShipment.RequestedPackageLineItems[1].Weight = new Weight();
                request.RequestedShipment.RequestedPackageLineItems[1].Weight.Units = WeightUnits.LB;
                request.RequestedShipment.RequestedPackageLineItems[1].Weight.UnitsSpecified = true;
                request.RequestedShipment.RequestedPackageLineItems[1].Weight.Value = 25.0M;
                request.RequestedShipment.RequestedPackageLineItems[1].Weight.ValueSpecified = true;
                // package dimensions
                request.RequestedShipment.RequestedPackageLineItems[1].Dimensions = new Dimensions();
                request.RequestedShipment.RequestedPackageLineItems[1].Dimensions.Length = "20";
                request.RequestedShipment.RequestedPackageLineItems[1].Dimensions.Width = "13";
                request.RequestedShipment.RequestedPackageLineItems[1].Dimensions.Height = "4";
                request.RequestedShipment.RequestedPackageLineItems[1].Dimensions.Units = LinearUnits.IN;
                request.RequestedShipment.RequestedPackageLineItems[1].Dimensions.UnitsSpecified = true;
                // insured value
                request.RequestedShipment.RequestedPackageLineItems[1].InsuredValue = new Money();
                request.RequestedShipment.RequestedPackageLineItems[1].InsuredValue.Amount = 500;
                request.RequestedShipment.RequestedPackageLineItems[1].InsuredValue.Currency = "USD";
            }
    
            private void ShowRateReply(RateReply reply)
            {
                foreach (RateReplyDetail rateReplyDetail in reply.RateReplyDetails)
                {
                    TableRow row1 = new TableRow();
                    TableRow row2 = new TableRow();
    
                    if (rateReplyDetail.ServiceTypeSpecified)
                    {
    
                        TableCell cell1 = new TableCell();
                        TableCell cell2 = new TableCell();
                        cell1.Text = "Service Type : ";
                        cell2.Text = rateReplyDetail.ServiceType.ToString();
                        row1.Cells.Add(cell1);
                        row1.Cells.Add(cell2);
                    }
                    if (rateReplyDetail.PackagingTypeSpecified)
                    {
                        TableCell cell3 = new TableCell();
                        TableCell cell4 = new TableCell();
                        cell3.Text = "Packaging Type : ";
                        cell4.Text = rateReplyDetail.PackagingType.ToString();
                        row2.Cells.Add(cell3);
                        row2.Cells.Add(cell4);
                    }
    
                    Table1.Rows.Add(row1);
                    Table1.Rows.Add(row2);
    
                    foreach (RatedShipmentDetail shipmentDetail in rateReplyDetail.RatedShipmentDetails)
                    {
                        ShowShipmentRateDetails(shipmentDetail);
                    }
                    ShowDeliveryDetails(rateReplyDetail);
                }
            }
    
            private void ShowShipmentRateDetails(RatedShipmentDetail shipmentDetail)
            {
                if (shipmentDetail == null) return;
                if (shipmentDetail.ShipmentRateDetail == null) return;
                ShipmentRateDetail rateDetail = shipmentDetail.ShipmentRateDetail;
                
                TableRow row1 = new TableRow();
                TableCell cell1 = new TableCell();
                TableCell cell0 = new TableCell();
                cell1.Text = "--- Shipment Rate Detail ---";
                cell0.Text = "";
                row1.Cells.Add(cell1);
                row1.Cells.Add(cell0);
                Table1.Rows.Add(row1);
    
                //
                TableRow row2 = new TableRow();
                TableCell cell2 = new TableCell();
                TableCell cell3 = new TableCell();
                cell2.Text = "RateType :";
                cell3.Text = rateDetail.RateType.ToString();
                row2.Cells.Add(cell2);
                row2.Cells.Add(cell3);
                Table1.Rows.Add(row2);
    
                if (rateDetail.TotalBillingWeight != null)
                {
                    TableRow row3 = new TableRow();
                    TableCell cell4 = new TableCell();
                    TableCell cell5 = new TableCell();
                    cell4.Text = "Total Billing Weight : ";
                    cell5.Text = rateDetail.TotalBillingWeight.Value.ToString() + " " + shipmentDetail.ShipmentRateDetail.TotalBillingWeight.Units.ToString();
                    row3.Cells.Add(cell4);
                    row3.Cells.Add(cell5);
                    Table1.Rows.Add(row3);
                }
                if (rateDetail.TotalBaseCharge != null)
                {
                    TableRow row3 = new TableRow();
                    TableCell cell4 = new TableCell();
                    TableCell cell5 = new TableCell();
                    cell4.Text = "Total Base Charge : ";
                    cell5.Text = rateDetail.TotalBaseCharge.Amount.ToString() + " " + rateDetail.TotalBaseCharge.Currency.ToString();
                    row3.Cells.Add(cell4);
                    row3.Cells.Add(cell5);
                    Table1.Rows.Add(row3);
                }
                if (rateDetail.TotalFreightDiscounts != null)
                {
                    TableRow row3 = new TableRow();
                    TableCell cell4 = new TableCell();
                    TableCell cell5 = new TableCell();
                    cell4.Text = "Total Freight Discounts : ";
                    cell5.Text = rateDetail.TotalFreightDiscounts.Amount.ToString() + " " + rateDetail.TotalFreightDiscounts.Currency.ToString();
                    row3.Cells.Add(cell4);
                    row3.Cells.Add(cell5);
                    Table1.Rows.Add(row3);
                }
                if (rateDetail.TotalSurcharges != null)
                {
                    TableRow row3 = new TableRow();
                    TableCell cell4 = new TableCell();
                    TableCell cell5 = new TableCell();
                    cell4.Text = "Total Surcharges : ";
                    cell5.Text = rateDetail.TotalSurcharges.Amount.ToString() + " " + rateDetail.TotalSurcharges.Currency.ToString();
                    row3.Cells.Add(cell4);
                    row3.Cells.Add(cell5);
                    Table1.Rows.Add(row3);
                }
                if (rateDetail.Surcharges != null)
                {
                    // Individual surcharge for each package
                    foreach (Surcharge surcharge in rateDetail.Surcharges)
                    {
                        TableRow row3 = new TableRow();
                        TableCell cell4 = new TableCell();
                        TableCell cell5 = new TableCell();
                        cell4.Text = surcharge.SurchargeType.ToString() + " surcharge ";
                        cell5.Text = surcharge.Amount.Amount.ToString() + " " + surcharge.Amount.Currency.ToString();
                        row3.Cells.Add(cell4);
                        row3.Cells.Add(cell5);
                        Table1.Rows.Add(row3);
                    }
                }
                if (rateDetail.TotalNetCharge != null)
                {
                    TableRow row3 = new TableRow();
                    TableCell cell4 = new TableCell();
                    TableCell cell5 = new TableCell();
                    cell4.Text = "Total Net Charge : ";
                    cell5.Text = rateDetail.TotalNetCharge.Amount.ToString() + " " + rateDetail.TotalNetCharge.Currency.ToString();
                    row3.Cells.Add(cell4);
                    row3.Cells.Add(cell5);
                    Table1.Rows.Add(row3);
                }
            }
    
            private void ShowDeliveryDetails(RateReplyDetail rateDetail)
            {
                if (rateDetail.DeliveryTimestampSpecified)
                {
                    TableRow row3 = new TableRow();
                    TableCell cell4 = new TableCell();
                    TableCell cell5 = new TableCell();
                    cell4.Text = "Delivery timestamp : ";
                    cell5.Text = rateDetail.DeliveryTimestamp.ToString();
                    row3.Cells.Add(cell4);
                    row3.Cells.Add(cell5);
                    Table1.Rows.Add(row3);
                }
                if (rateDetail.TransitTimeSpecified)
                {
                    TableRow row3 = new TableRow();
                    TableCell cell4 = new TableCell();
                    TableCell cell5 = new TableCell();
                    cell4.Text = "Transit time : ";
                    cell5.Text = rateDetail.TransitTime.ToString();
                    row3.Cells.Add(cell4);
                    row3.Cells.Add(cell5);
                    Table1.Rows.Add(row3);
                }
            }
    
            private void ShowNotifications(RateReply reply)
            {
                TableRow row1 = new TableRow();
                TableCell cell1 = new TableCell();
                TableCell cell0 = new TableCell();
                cell1.Text = "Notifications";
                cell0.Text = "";
                row1.Cells.Add(cell1);
                row1.Cells.Add(cell0);
                Table1.Rows.Add(row1);
    
                for (int i = 0; i < reply.Notifications.Length; i++)
                {
                    TableRow row2 = new TableRow();
                    TableRow row3 = new TableRow();
                    TableRow row4 = new TableRow();
                    TableRow row5 = new TableRow();
                    TableRow row6 = new TableRow();
    
                    TableCell cell2 = new TableCell();
                    TableCell cell3 = new TableCell();
                    TableCell cell4 = new TableCell();
                    TableCell cell5 = new TableCell();
                    TableCell cell6 = new TableCell();
                    TableCell cell7 = new TableCell();
                    TableCell cell8 = new TableCell();
                    TableCell cell9 = new TableCell();
                    TableCell cell10 = new TableCell();
                    TableCell cell11 = new TableCell();
    
                    Notification notification = reply.Notifications[i];
                    
                    cell2.Text = "Notification no. ";
                    cell3.Text = i.ToString();
                    row2.Cells.Add(cell2);
                    row2.Cells.Add(cell3);
    
                    cell4.Text = "Severity : ";
                    cell5.Text = notification.Severity.ToString();
                    row3.Cells.Add(cell4);
                    row3.Cells.Add(cell5);
    
                    cell6.Text = "Code : ";
                    cell7.Text = notification.Code.ToString();
                    row4.Cells.Add(cell6);
                    row4.Cells.Add(cell7);
    
                    cell8.Text = "Message : ";
                    cell9.Text = notification.Message.ToString();
                    row5.Cells.Add(cell8);
                    row5.Cells.Add(cell9);
    
                    cell10.Text = "Source : ";
                    cell11.Text = notification.Source.ToString();
                    row6.Cells.Add(cell10);
                    row6.Cells.Add(cell11);
    
                    Table1.Rows.Add(row2);
                    Table1.Rows.Add(row3);
                    Table1.Rows.Add(row4);
                    Table1.Rows.Add(row5);
                    Table1.Rows.Add(row6);
                }
            }
        }
    }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, November 7, 2013 7:06 AM

All replies

  • User-741098373 posted

    Well, I don't know where you are facing problem exactly with the sample. Anyway I registered and downloaded the sample. I'll try to explain the thing...

    1. Register the Web Reference (i.e. Web Service) as in the Sample Application.

    2. Setup web.config file according to app.config service setings.

    3. Initialize RateRequest and RateService object as done in Sample Application

    4. Build RateRequest object as in Sample Application according to your Form Data

    5. Now when you get RateReply after successfull request, you can parse the object by it's properties as shown in Sample Application

    Thursday, November 7, 2013 2:50 AM
  • User540310021 posted
    using System;
    using System.Collections.Generic;
    using System.Configuration;
    using System.Linq;
    using System.Runtime.Remoting.Messaging;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.Services.Protocols;
    using System.Web.UI.WebControls.WebParts;
    using RateWebServiceClient.RateServiceWebReference;
    
    namespace FedEx
    {
        public partial class Default : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
             
            }
    
            private void ShowRateReply(RateReply reply)
            {
                TableRow row = new TableRow();
                foreach (RateReplyDetail rateReplyDetail in reply.RateReplyDetails)
                {
                    if (rateReplyDetail.ServiceTypeSpecified)
                    {
                        TableCell servicetype = new TableCell();
                        servicetype.Text = string.Format("Service Type: {0}", rateReplyDetail.ServiceType);
                        row.Cells.Add(servicetype);
                        Table3.Rows.Add(row);
                    }
                    if (rateReplyDetail.PackagingTypeSpecified)
                    {
                        TableCell packageingtype = new TableCell();
                        packageingtype.Text = string.Format("Packaging Type: {0}", rateReplyDetail.PackagingType);
                        row.Cells.Add(packageingtype);
                        Table3.Rows.Add(row);
                    }
                    foreach (RatedShipmentDetail shipmentDetail in rateReplyDetail.RatedShipmentDetails)
                    {
                        ShowShipmentRateDetails(shipmentDetail);
                    }
                    ShowDeliveryDetails(rateReplyDetail);
                }
            }
    
            private  RateRequest CreateRateRequest()
            {
                try
                {
                    RateRequest request = new RateRequest();
                    request.WebAuthenticationDetail = new WebAuthenticationDetail();
                    request.WebAuthenticationDetail.UserCredential = new WebAuthenticationCredential();
                    request.WebAuthenticationDetail.UserCredential.Key = ConfigurationManager.AppSettings["UserKey"];
                    request.WebAuthenticationDetail.UserCredential.Password = ConfigurationManager.AppSettings["UserPassword"];
    
                    request.ClientDetail = new ClientDetail();
                    request.ClientDetail.AccountNumber = ConfigurationManager.AppSettings["AccountNumber"];
                    request.ClientDetail.MeterNumber = ConfigurationManager.AppSettings["MeterNumber"];
    
                    request.TransactionDetail = new TransactionDetail();
                    request.TransactionDetail.CustomerTransactionId = Guid.NewGuid().ToString();
    
                    request.Version = new VersionId();
    
                    request.ReturnTransitAndCommit = true;
                    request.ReturnTransitAndCommitSpecified = true;
    
                    SetShipmentDetails(request);
    
                    return request;
    
                }
                catch (Exception ex)
                {
                    HttpContext context = HttpContext.Current;
                    context.Response.Write(ex.Message);
                    context.Response.Write(ex.InnerException);
                    return null;
                }
            }
    
           private void SetShipmentDetails(RateRequest request)
            {
                request.RequestedShipment = new RequestedShipment();
                request.RequestedShipment.ShipTimestamp = DateTime.UtcNow;
                request.RequestedShipment.ShipTimestampSpecified = true;
                request.RequestedShipment.DropoffType = DropoffType.REGULAR_PICKUP;
                //request.RequestedShipment.ServiceType = ServiceType.INTERNATIONAL_PRIORITY;
                request.RequestedShipment.ServiceTypeSpecified = false;
                request.RequestedShipment.PackagingType = PackagingType.YOUR_PACKAGING;
                request.RequestedShipment.PackagingTypeSpecified = true;
    
                SetOrigin(request);
    
                SetDestination(request);
    
                SetPackageLineItems(request);
    
                request.RequestedShipment.TotalInsuredValue = new Money();
                request.RequestedShipment.TotalInsuredValue.Amount = 100;
                request.RequestedShipment.TotalInsuredValue.Currency = "USD";
                //
                request.RequestedShipment.RateRequestTypes = new RateRequestType[2];
                request.RequestedShipment.RateRequestTypes[0] = RateRequestType.ACCOUNT;
                request.RequestedShipment.RateRequestTypes[1] = RateRequestType.LIST;
                request.RequestedShipment.PackageCount = "2";
            }
    
           //private static void SetPackageLineItems(RateRequest request)
           //{
           //    request.RequestedShipment.RequestedPackageLineItems = new RequestedPackageLineItem[2];
           //    request.RequestedShipment.RequestedPackageLineItems[0] = new RequestedPackageLineItem();
           //    request.RequestedShipment.RequestedPackageLineItems[0].SequenceNumber = "1"; // package sequence number
           //    request.RequestedShipment.RequestedPackageLineItems[0].GroupPackageCount = "1";
           //    // package weight
           //    request.RequestedShipment.RequestedPackageLineItems[0].Weight = new Weight();
           //    request.RequestedShipment.RequestedPackageLineItems[0].Weight.Units = WeightUnits.LB;
           //    request.RequestedShipment.RequestedPackageLineItems[0].Weight.UnitsSpecified = true;
           //    request.RequestedShipment.RequestedPackageLineItems[0].Weight.Value = 15.0M;
           //    request.RequestedShipment.RequestedPackageLineItems[0].Weight.ValueSpecified = true;
           //    // package dimensions
           //    request.RequestedShipment.RequestedPackageLineItems[0].Dimensions = new Dimensions();
           //    request.RequestedShipment.RequestedPackageLineItems[0].Dimensions.Length = "10";
           //    request.RequestedShipment.RequestedPackageLineItems[0].Dimensions.Width = "13";
           //    request.RequestedShipment.RequestedPackageLineItems[0].Dimensions.Height = "4";
           //    request.RequestedShipment.RequestedPackageLineItems[0].Dimensions.Units = LinearUnits.IN;
           //    request.RequestedShipment.RequestedPackageLineItems[0].Dimensions.UnitsSpecified = true;
           //    // insured value
           //    request.RequestedShipment.RequestedPackageLineItems[0].InsuredValue = new Money();
           //    request.RequestedShipment.RequestedPackageLineItems[0].InsuredValue.Amount = 100;
           //    request.RequestedShipment.RequestedPackageLineItems[0].InsuredValue.Currency = "USD";
           //    //
           //    request.RequestedShipment.RequestedPackageLineItems[1] = new RequestedPackageLineItem();
           //    request.RequestedShipment.RequestedPackageLineItems[1].SequenceNumber = "2"; // package sequence number
           //    request.RequestedShipment.RequestedPackageLineItems[1].GroupPackageCount = "1";
           //    // package weight
           //    request.RequestedShipment.RequestedPackageLineItems[1].Weight = new Weight();
           //    request.RequestedShipment.RequestedPackageLineItems[1].Weight.Units = WeightUnits.LB;
           //    request.RequestedShipment.RequestedPackageLineItems[1].Weight.UnitsSpecified = true;
           //    request.RequestedShipment.RequestedPackageLineItems[1].Weight.Value = 25.0M;
           //    request.RequestedShipment.RequestedPackageLineItems[1].Weight.ValueSpecified = true;
           //    // package dimensions
           //    request.RequestedShipment.RequestedPackageLineItems[1].Dimensions = new Dimensions();
           //    request.RequestedShipment.RequestedPackageLineItems[1].Dimensions.Length = "20";
           //    request.RequestedShipment.RequestedPackageLineItems[1].Dimensions.Width = "13";
           //    request.RequestedShipment.RequestedPackageLineItems[1].Dimensions.Height = "4";
           //    request.RequestedShipment.RequestedPackageLineItems[1].Dimensions.Units = LinearUnits.IN;
           //    request.RequestedShipment.RequestedPackageLineItems[1].Dimensions.UnitsSpecified = true;
           //    // insured value
           //    request.RequestedShipment.RequestedPackageLineItems[1].InsuredValue = new Money();
           //    request.RequestedShipment.RequestedPackageLineItems[1].InsuredValue.Amount = 500;
           //    request.RequestedShipment.RequestedPackageLineItems[1].InsuredValue.Currency = "USD";
           //}
            private void SetPackageLineItems(RateRequest request)
            {
                
                request.RequestedShipment.RequestedPackageLineItems = new RequestedPackageLineItem[1];
                request.RequestedShipment.RequestedPackageLineItems[0] = new RequestedPackageLineItem();
                request.RequestedShipment.RequestedPackageLineItems[0].SequenceNumber = "1";
                request.RequestedShipment.RequestedPackageLineItems[0].GroupPackageCount = "1";
    
                // package weight
                request.RequestedShipment.RequestedPackageLineItems[0].Weight = new Weight();
                request.RequestedShipment.RequestedPackageLineItems[0].Weight.Units = WeightUnits.LB;
                request.RequestedShipment.RequestedPackageLineItems[0].Weight.UnitsSpecified = true;
                request.RequestedShipment.RequestedPackageLineItems[0].Weight.Value = Convert.ToDecimal(tbWeight.Text);
    
    
                //package dimensions
                request.RequestedShipment.RequestedPackageLineItems[0].Dimensions = new Dimensions();
                request.RequestedShipment.RequestedPackageLineItems[0].Dimensions.Length = tbLength.Text;
                request.RequestedShipment.RequestedPackageLineItems[0].Dimensions.Width = tbWidth.Text;
                request.RequestedShipment.RequestedPackageLineItems[0].Dimensions.Height = tbHeight.Text;
                request.RequestedShipment.RequestedPackageLineItems[0].Dimensions.Units = LinearUnits.IN;
                request.RequestedShipment.RequestedPackageLineItems[0].Dimensions.UnitsSpecified = true;
    
                //insured value
                request.RequestedShipment.RequestedPackageLineItems[0].InsuredValue = new Money();
                request.RequestedShipment.RequestedPackageLineItems[0].InsuredValue.Amount = 100;
                request.RequestedShipment.RequestedPackageLineItems[0].InsuredValue.Currency = "USD";
    
            }
    
            private void SetDestination(RateRequest request)
            {
                request.RequestedShipment.Recipient = new Party();
                request.RequestedShipment.Recipient.Address = new Address();
                string[] strLines = tbdsStreet.Text.Split(new string[]{Environment.NewLine}, StringSplitOptions.None);
                request.RequestedShipment.Recipient.Address.StreetLines = strLines;
                request.RequestedShipment.Recipient.Address.City = tbdsCity.Text;
                request.RequestedShipment.Recipient.Address.StateOrProvinceCode = tbdsStateCode.Text;
                request.RequestedShipment.Recipient.Address.PostalCode = tbdsPostalCode.Text;
                request.RequestedShipment.Recipient.Address.CountryCode = tbdsCountryCode.Text;
            }
    
            private void SetOrigin(RateRequest request)
            {
                request.RequestedShipment.Shipper = new Party();
                request.RequestedShipment.Shipper.Address = new Address();
                string[] strLines = tbStreetLine.Text.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
                request.RequestedShipment.Shipper.Address.StreetLines = strLines;
                request.RequestedShipment.Shipper.Address.City = tbCity.Text;
                request.RequestedShipment.Shipper.Address.StateOrProvinceCode = tbStateCode.Text;
                request.RequestedShipment.Shipper.Address.PostalCode = tbPostalCode.Text;
                request.RequestedShipment.Shipper.Address.CountryCode = tbCountryCode.Text;
            }
    
            private void ShowShipmentRateDetails(RatedShipmentDetail shipmentDetail)
            {
                if (shipmentDetail == null) return;
                if (shipmentDetail.ShipmentRateDetail == null) return;
                ShipmentRateDetail rateDetail = shipmentDetail.ShipmentRateDetail;
                TableRow row = new TableRow();
                TableCell rateType = new TableCell();
                rateType.Text = rateDetail.RateType.ToString();
                row.Cells.Add(rateType);
                Table1.Rows.Add(row);
    
                if (rateDetail.TotalBillingWeight !=null)
                {
                    TableCell totalweight = new TableCell();
                    totalweight.Text = string.Format("Total Bill weight: {0} {1}", rateDetail.TotalBillingWeight.Value,shipmentDetail.ShipmentRateDetail.TotalBillingWeight.Units);
                    row.Cells.Add(totalweight);
                    Table1.Rows.Add(row);
                }
    
                if (rateDetail.TotalBaseCharge != null)
                {
                    TableCell totalbaseCharge = new TableCell();
                    totalbaseCharge.Text = string.Format("Total Base Charge: {0} {1}", rateDetail.TotalBaseCharge.Amount,rateDetail.TotalBaseCharge.Currency);
                    row.Cells.Add(totalbaseCharge);
                    Table1.Rows.Add(row);
                }
                if (rateDetail.TotalFreightDiscounts != null)
                {
                    TableCell totalFreight = new TableCell();
                    totalFreight.Text =
                    string.Format("Total Freight Discounts: {0} {1}", rateDetail.TotalFreightDiscounts.Amount,
                        rateDetail.TotalFreightDiscounts.Currency);
                    row.Cells.Add(totalFreight);
                    Table1.Rows.Add(row);
                }
                if (rateDetail.TotalSurcharges !=null)
                {
                    TableCell totalSurcharges = new TableCell();
                    totalSurcharges.Text = string.Format("Total Surcharges: {0} {1}", rateDetail.TotalSurcharges.Amount,
                        rateDetail.TotalSurcharges.Currency);
                    row.Cells.Add(totalSurcharges);
                    Table1.Rows.Add(row);
                }
                if (rateDetail.Surcharges != null)
                {
                    foreach (Surcharge surcharge in rateDetail.Surcharges)
                    {
                        TableCell surcharges = new TableCell();
                        surcharges.Text = string.Format("{0} surcharge {1} {2}", surcharge.SurchargeType, surcharge.Amount,
                            surcharge.Amount.Currency);
    
                        row.Cells.Add(surcharges);
                        Table1.Rows.Add(row);
                    }
                }
                if (rateDetail.TotalNetCharge != null)
                {
                    TableCell totalnetcharge = new TableCell();
                    totalnetcharge.Text = string.Format("Total net charge: {0} {1}", rateDetail.TotalNetCharge.Amount,
                        rateDetail.TotalNetCharge.Currency);
                    row.Cells.Add(totalnetcharge);
                    Table1.Rows.Add(row);
                }
            }
    
            private void ShowDeliveryDetails(RateReplyDetail rateDetail)
            {
                TableRow row = new TableRow();
                if (rateDetail.DeliveryTimestampSpecified)
                {
                    TableCell deilverycell = new TableCell();
                    deilverycell.Text = string.Format("Delivery timestamp {0}", rateDetail.DeliveryTimestamp);
                    row.Cells.Add(deilverycell);
                    Table2.Rows.Add(row);
    
                }
    
                if (rateDetail.TransitTimeSpecified)
                {
                    TableCell transittime = new TableCell();
                    transittime.Text = string.Format("Transit time: {0}", rateDetail.TransitTime);
                    row.Cells.Add(transittime);
                    Table2.Rows.Add(row);
                }
            }
            protected void Button1_Click(object sender, EventArgs e)
            {
                RateRequest request = CreateRateRequest();
    
                RateService service = new RateService();
    
                service.Url = "https://wsbeta.fedex.com:443/web-services/rate";
    
                try
                {
                    RateReply reply = service.getRates(request);
    
                    if (reply.HighestSeverity == NotificationSeverityType.SUCCESS ||
                        reply.HighestSeverity == NotificationSeverityType.NOTE ||
                        reply.HighestSeverity == NotificationSeverityType.WARNING)
                    {
                        ShowRateReply(reply);
                    }
                    else
                    {
                       
                    }
                }
                catch (SoapException ex)
                {
                    HttpContext context = HttpContext.Current;
                    context.Response.Write(ex.Detail.InnerText);
                }
                catch (Exception ex)
                {
                    HttpContext context = HttpContext.Current;
                    context.Response.Write(ex.Message);
                }
            }
        }
    }

    This is my code. Please guide me.

    Thursday, November 7, 2013 5:42 AM
  • Thursday, November 7, 2013 5:49 AM
  • User-741098373 posted

    Took sometime to reply, as I was writing the code.

    Here's the full project : https://www.dropbox.com/s/24oa4za3ma6sx8g/WebApplication2.rar

    Here's your whole source

    ASPX Page:

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1.Default" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:ScriptManager ID="ScriptManager1" runat="server">
            </asp:ScriptManager>
    
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                    <asp:ListBox ID="ListBox1" runat="server" AppendDataBoundItems="true"></asp:ListBox>
                    <br />
                    <asp:Button ID="btnGetRate" runat="server" Text="Get Rate"
                        onclick="btnGetRate_Click" />
                    <br />
                    <asp:Table ID="Table1" runat="server">
                    </asp:Table>
                </ContentTemplate>
            </asp:UpdatePanel>
        </div>
        </form>
    </body>
    </html>

    I'm using the listbox to show any error details.

    Code-Behind:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.Services.Protocols;
    using WebApplication1.RateServiceReference;
    
    namespace WebApplication1
    {
        public partial class Default : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
    
            }
    
            protected void btnGetRate_Click(object sender, EventArgs e)
            {
                RateRequest request = CreateRateRequest();
                //
                RateService service = new RateService();
    
                try
                {
                    // Call the web service passing in a RateRequest and returning a RateReply
                    RateReply reply = service.getRates(request);
    
                    if (reply.HighestSeverity == NotificationSeverityType.SUCCESS || reply.HighestSeverity == NotificationSeverityType.NOTE || reply.HighestSeverity == NotificationSeverityType.WARNING)
                    {
                        ShowRateReply(reply);
                    }
                    ShowNotifications(reply);
                }
                catch (SoapException ex)
                {
                    ListBox1.Items.Add(ex.Detail.InnerText);
                }
                catch (Exception ex)
                {
                    ListBox1.Items.Add(ex.Message);
                }
            }
    
            private RateRequest CreateRateRequest()
            {
                // Build a RateRequest
                RateRequest request = new RateRequest();
                //
                request.WebAuthenticationDetail = new WebAuthenticationDetail();
                request.WebAuthenticationDetail.UserCredential = new WebAuthenticationCredential();
                request.WebAuthenticationDetail.UserCredential.Key = "XXX"; // Replace "XXX" with the Key
                request.WebAuthenticationDetail.UserCredential.Password = "XXX"; // Replace "XXX" with the Password
                
                //
                request.ClientDetail = new ClientDetail();
                request.ClientDetail.AccountNumber = "XXX"; // Replace "XXX" with the client's account number
                request.ClientDetail.MeterNumber = "XXX"; // Replace "XXX" with the client's meter number
                
                //
                request.TransactionDetail = new TransactionDetail();
                request.TransactionDetail.CustomerTransactionId = "***Rate v14 Request using VC#***"; // This is a reference field for the customer.  Any value can be used and will be provided in the response.
                //
                request.Version = new VersionId();
                //
                request.ReturnTransitAndCommit = true;
                request.ReturnTransitAndCommitSpecified = true;
                //
                SetShipmentDetails(request);
                //
                return request;
            }
    
            private void SetShipmentDetails(RateRequest request)
            {
                request.RequestedShipment = new RequestedShipment();
                request.RequestedShipment.ShipTimestamp = DateTime.Now; // Shipping date and time
                request.RequestedShipment.ShipTimestampSpecified = true;
                request.RequestedShipment.DropoffType = DropoffType.REGULAR_PICKUP; //Drop off types are BUSINESS_SERVICE_CENTER, DROP_BOX, REGULAR_PICKUP, REQUEST_COURIER, STATION
                request.RequestedShipment.ServiceType = ServiceType.INTERNATIONAL_PRIORITY; // Service types are STANDARD_OVERNIGHT, PRIORITY_OVERNIGHT, FEDEX_GROUND ...
                request.RequestedShipment.ServiceTypeSpecified = true;
                request.RequestedShipment.PackagingType = PackagingType.YOUR_PACKAGING; // Packaging type FEDEX_BOK, FEDEX_PAK, FEDEX_TUBE, YOUR_PACKAGING, ...
                request.RequestedShipment.PackagingTypeSpecified = true;
                //
                SetOrigin(request);
                //
                SetDestination(request);
                //
                SetPackageLineItems(request);
                //
                request.RequestedShipment.TotalInsuredValue = new Money();
                request.RequestedShipment.TotalInsuredValue.Amount = 100;
                request.RequestedShipment.TotalInsuredValue.Currency = "USD";
                //
                request.RequestedShipment.RateRequestTypes = new RateRequestType[2];
                request.RequestedShipment.RateRequestTypes[0] = RateRequestType.ACCOUNT;
                request.RequestedShipment.RateRequestTypes[1] = RateRequestType.LIST;
                request.RequestedShipment.PackageCount = "2";
            }
    
            private void SetOrigin(RateRequest request)
            {
                request.RequestedShipment.Shipper = new Party();
                request.RequestedShipment.Shipper.Address = new Address();
                request.RequestedShipment.Shipper.Address.StreetLines = new string[1] { "SHIPPER ADDRESS LINE 1" };
                request.RequestedShipment.Shipper.Address.City = "COLLIERVILLE";
                request.RequestedShipment.Shipper.Address.StateOrProvinceCode = "TN";
                request.RequestedShipment.Shipper.Address.PostalCode = "38017";
                request.RequestedShipment.Shipper.Address.CountryCode = "US";
            }
    
            private void SetDestination(RateRequest request)
            {
                request.RequestedShipment.Recipient = new Party();
                request.RequestedShipment.Recipient.Address = new Address();
                request.RequestedShipment.Recipient.Address.StreetLines = new string[1] { "RECIPIENT ADDRESS LINE 1" };
                request.RequestedShipment.Recipient.Address.City = "Montreal";
                request.RequestedShipment.Recipient.Address.StateOrProvinceCode = "PQ";
                request.RequestedShipment.Recipient.Address.PostalCode = "H1E1A1";
                request.RequestedShipment.Recipient.Address.CountryCode = "CA";
            }
    
            private void SetPackageLineItems(RateRequest request)
            {
                request.RequestedShipment.RequestedPackageLineItems = new RequestedPackageLineItem[2];
                request.RequestedShipment.RequestedPackageLineItems[0] = new RequestedPackageLineItem();
                request.RequestedShipment.RequestedPackageLineItems[0].SequenceNumber = "1"; // package sequence number
                request.RequestedShipment.RequestedPackageLineItems[0].GroupPackageCount = "1";
                // package weight
                request.RequestedShipment.RequestedPackageLineItems[0].Weight = new Weight();
                request.RequestedShipment.RequestedPackageLineItems[0].Weight.Units = WeightUnits.LB;
                request.RequestedShipment.RequestedPackageLineItems[0].Weight.UnitsSpecified = true;
                request.RequestedShipment.RequestedPackageLineItems[0].Weight.Value = 15.0M;
                request.RequestedShipment.RequestedPackageLineItems[0].Weight.ValueSpecified = true;
                // package dimensions
                request.RequestedShipment.RequestedPackageLineItems[0].Dimensions = new Dimensions();
                request.RequestedShipment.RequestedPackageLineItems[0].Dimensions.Length = "10";
                request.RequestedShipment.RequestedPackageLineItems[0].Dimensions.Width = "13";
                request.RequestedShipment.RequestedPackageLineItems[0].Dimensions.Height = "4";
                request.RequestedShipment.RequestedPackageLineItems[0].Dimensions.Units = LinearUnits.IN;
                request.RequestedShipment.RequestedPackageLineItems[0].Dimensions.UnitsSpecified = true;
                // insured value
                request.RequestedShipment.RequestedPackageLineItems[0].InsuredValue = new Money();
                request.RequestedShipment.RequestedPackageLineItems[0].InsuredValue.Amount = 100;
                request.RequestedShipment.RequestedPackageLineItems[0].InsuredValue.Currency = "USD";
                //
                request.RequestedShipment.RequestedPackageLineItems[1] = new RequestedPackageLineItem();
                request.RequestedShipment.RequestedPackageLineItems[1].SequenceNumber = "2"; // package sequence number
                request.RequestedShipment.RequestedPackageLineItems[1].GroupPackageCount = "1";
                // package weight
                request.RequestedShipment.RequestedPackageLineItems[1].Weight = new Weight();
                request.RequestedShipment.RequestedPackageLineItems[1].Weight.Units = WeightUnits.LB;
                request.RequestedShipment.RequestedPackageLineItems[1].Weight.UnitsSpecified = true;
                request.RequestedShipment.RequestedPackageLineItems[1].Weight.Value = 25.0M;
                request.RequestedShipment.RequestedPackageLineItems[1].Weight.ValueSpecified = true;
                // package dimensions
                request.RequestedShipment.RequestedPackageLineItems[1].Dimensions = new Dimensions();
                request.RequestedShipment.RequestedPackageLineItems[1].Dimensions.Length = "20";
                request.RequestedShipment.RequestedPackageLineItems[1].Dimensions.Width = "13";
                request.RequestedShipment.RequestedPackageLineItems[1].Dimensions.Height = "4";
                request.RequestedShipment.RequestedPackageLineItems[1].Dimensions.Units = LinearUnits.IN;
                request.RequestedShipment.RequestedPackageLineItems[1].Dimensions.UnitsSpecified = true;
                // insured value
                request.RequestedShipment.RequestedPackageLineItems[1].InsuredValue = new Money();
                request.RequestedShipment.RequestedPackageLineItems[1].InsuredValue.Amount = 500;
                request.RequestedShipment.RequestedPackageLineItems[1].InsuredValue.Currency = "USD";
            }
    
            private void ShowRateReply(RateReply reply)
            {
                foreach (RateReplyDetail rateReplyDetail in reply.RateReplyDetails)
                {
                    TableRow row1 = new TableRow();
                    TableRow row2 = new TableRow();
    
                    if (rateReplyDetail.ServiceTypeSpecified)
                    {
    
                        TableCell cell1 = new TableCell();
                        TableCell cell2 = new TableCell();
                        cell1.Text = "Service Type : ";
                        cell2.Text = rateReplyDetail.ServiceType.ToString();
                        row1.Cells.Add(cell1);
                        row1.Cells.Add(cell2);
                    }
                    if (rateReplyDetail.PackagingTypeSpecified)
                    {
                        TableCell cell3 = new TableCell();
                        TableCell cell4 = new TableCell();
                        cell3.Text = "Packaging Type : ";
                        cell4.Text = rateReplyDetail.PackagingType.ToString();
                        row2.Cells.Add(cell3);
                        row2.Cells.Add(cell4);
                    }
    
                    Table1.Rows.Add(row1);
                    Table1.Rows.Add(row2);
    
                    foreach (RatedShipmentDetail shipmentDetail in rateReplyDetail.RatedShipmentDetails)
                    {
                        ShowShipmentRateDetails(shipmentDetail);
                    }
                    ShowDeliveryDetails(rateReplyDetail);
                }
            }
    
            private void ShowShipmentRateDetails(RatedShipmentDetail shipmentDetail)
            {
                if (shipmentDetail == null) return;
                if (shipmentDetail.ShipmentRateDetail == null) return;
                ShipmentRateDetail rateDetail = shipmentDetail.ShipmentRateDetail;
                
                TableRow row1 = new TableRow();
                TableCell cell1 = new TableCell();
                TableCell cell0 = new TableCell();
                cell1.Text = "--- Shipment Rate Detail ---";
                cell0.Text = "";
                row1.Cells.Add(cell1);
                row1.Cells.Add(cell0);
                Table1.Rows.Add(row1);
    
                //
                TableRow row2 = new TableRow();
                TableCell cell2 = new TableCell();
                TableCell cell3 = new TableCell();
                cell2.Text = "RateType :";
                cell3.Text = rateDetail.RateType.ToString();
                row2.Cells.Add(cell2);
                row2.Cells.Add(cell3);
                Table1.Rows.Add(row2);
    
                if (rateDetail.TotalBillingWeight != null)
                {
                    TableRow row3 = new TableRow();
                    TableCell cell4 = new TableCell();
                    TableCell cell5 = new TableCell();
                    cell4.Text = "Total Billing Weight : ";
                    cell5.Text = rateDetail.TotalBillingWeight.Value.ToString() + " " + shipmentDetail.ShipmentRateDetail.TotalBillingWeight.Units.ToString();
                    row3.Cells.Add(cell4);
                    row3.Cells.Add(cell5);
                    Table1.Rows.Add(row3);
                }
                if (rateDetail.TotalBaseCharge != null)
                {
                    TableRow row3 = new TableRow();
                    TableCell cell4 = new TableCell();
                    TableCell cell5 = new TableCell();
                    cell4.Text = "Total Base Charge : ";
                    cell5.Text = rateDetail.TotalBaseCharge.Amount.ToString() + " " + rateDetail.TotalBaseCharge.Currency.ToString();
                    row3.Cells.Add(cell4);
                    row3.Cells.Add(cell5);
                    Table1.Rows.Add(row3);
                }
                if (rateDetail.TotalFreightDiscounts != null)
                {
                    TableRow row3 = new TableRow();
                    TableCell cell4 = new TableCell();
                    TableCell cell5 = new TableCell();
                    cell4.Text = "Total Freight Discounts : ";
                    cell5.Text = rateDetail.TotalFreightDiscounts.Amount.ToString() + " " + rateDetail.TotalFreightDiscounts.Currency.ToString();
                    row3.Cells.Add(cell4);
                    row3.Cells.Add(cell5);
                    Table1.Rows.Add(row3);
                }
                if (rateDetail.TotalSurcharges != null)
                {
                    TableRow row3 = new TableRow();
                    TableCell cell4 = new TableCell();
                    TableCell cell5 = new TableCell();
                    cell4.Text = "Total Surcharges : ";
                    cell5.Text = rateDetail.TotalSurcharges.Amount.ToString() + " " + rateDetail.TotalSurcharges.Currency.ToString();
                    row3.Cells.Add(cell4);
                    row3.Cells.Add(cell5);
                    Table1.Rows.Add(row3);
                }
                if (rateDetail.Surcharges != null)
                {
                    // Individual surcharge for each package
                    foreach (Surcharge surcharge in rateDetail.Surcharges)
                    {
                        TableRow row3 = new TableRow();
                        TableCell cell4 = new TableCell();
                        TableCell cell5 = new TableCell();
                        cell4.Text = surcharge.SurchargeType.ToString() + " surcharge ";
                        cell5.Text = surcharge.Amount.Amount.ToString() + " " + surcharge.Amount.Currency.ToString();
                        row3.Cells.Add(cell4);
                        row3.Cells.Add(cell5);
                        Table1.Rows.Add(row3);
                    }
                }
                if (rateDetail.TotalNetCharge != null)
                {
                    TableRow row3 = new TableRow();
                    TableCell cell4 = new TableCell();
                    TableCell cell5 = new TableCell();
                    cell4.Text = "Total Net Charge : ";
                    cell5.Text = rateDetail.TotalNetCharge.Amount.ToString() + " " + rateDetail.TotalNetCharge.Currency.ToString();
                    row3.Cells.Add(cell4);
                    row3.Cells.Add(cell5);
                    Table1.Rows.Add(row3);
                }
            }
    
            private void ShowDeliveryDetails(RateReplyDetail rateDetail)
            {
                if (rateDetail.DeliveryTimestampSpecified)
                {
                    TableRow row3 = new TableRow();
                    TableCell cell4 = new TableCell();
                    TableCell cell5 = new TableCell();
                    cell4.Text = "Delivery timestamp : ";
                    cell5.Text = rateDetail.DeliveryTimestamp.ToString();
                    row3.Cells.Add(cell4);
                    row3.Cells.Add(cell5);
                    Table1.Rows.Add(row3);
                }
                if (rateDetail.TransitTimeSpecified)
                {
                    TableRow row3 = new TableRow();
                    TableCell cell4 = new TableCell();
                    TableCell cell5 = new TableCell();
                    cell4.Text = "Transit time : ";
                    cell5.Text = rateDetail.TransitTime.ToString();
                    row3.Cells.Add(cell4);
                    row3.Cells.Add(cell5);
                    Table1.Rows.Add(row3);
                }
            }
    
            private void ShowNotifications(RateReply reply)
            {
                TableRow row1 = new TableRow();
                TableCell cell1 = new TableCell();
                TableCell cell0 = new TableCell();
                cell1.Text = "Notifications";
                cell0.Text = "";
                row1.Cells.Add(cell1);
                row1.Cells.Add(cell0);
                Table1.Rows.Add(row1);
    
                for (int i = 0; i < reply.Notifications.Length; i++)
                {
                    TableRow row2 = new TableRow();
                    TableRow row3 = new TableRow();
                    TableRow row4 = new TableRow();
                    TableRow row5 = new TableRow();
                    TableRow row6 = new TableRow();
    
                    TableCell cell2 = new TableCell();
                    TableCell cell3 = new TableCell();
                    TableCell cell4 = new TableCell();
                    TableCell cell5 = new TableCell();
                    TableCell cell6 = new TableCell();
                    TableCell cell7 = new TableCell();
                    TableCell cell8 = new TableCell();
                    TableCell cell9 = new TableCell();
                    TableCell cell10 = new TableCell();
                    TableCell cell11 = new TableCell();
    
                    Notification notification = reply.Notifications[i];
                    
                    cell2.Text = "Notification no. ";
                    cell3.Text = i.ToString();
                    row2.Cells.Add(cell2);
                    row2.Cells.Add(cell3);
    
                    cell4.Text = "Severity : ";
                    cell5.Text = notification.Severity.ToString();
                    row3.Cells.Add(cell4);
                    row3.Cells.Add(cell5);
    
                    cell6.Text = "Code : ";
                    cell7.Text = notification.Code.ToString();
                    row4.Cells.Add(cell6);
                    row4.Cells.Add(cell7);
    
                    cell8.Text = "Message : ";
                    cell9.Text = notification.Message.ToString();
                    row5.Cells.Add(cell8);
                    row5.Cells.Add(cell9);
    
                    cell10.Text = "Source : ";
                    cell11.Text = notification.Source.ToString();
                    row6.Cells.Add(cell10);
                    row6.Cells.Add(cell11);
    
                    Table1.Rows.Add(row2);
                    Table1.Rows.Add(row3);
                    Table1.Rows.Add(row4);
                    Table1.Rows.Add(row5);
                    Table1.Rows.Add(row6);
                }
            }
        }
    }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, November 7, 2013 7:06 AM