/// <summary>
 /// Gets the available services method.
 /// See the API v15 documention for more information - https://github.com/despatchbay/api.v15/wiki/Shipping-Service
 /// </summary>
 /// <returns>an array of ServiceType[] </returns>
 /// <param name="shipment">Shipment.</param>
 private static ServiceType[] GetAvailableServicesMethod(ShipmentRequestType shipment)
 {
     ServiceType[] availableServices = null;
     Service = GetAuthoriseService();
     try {
         // Call the GetDomesticServices soap service
         availableServices = Service.GetAvailableServices(shipment);
     } catch (Exception soapEx) {
         Console.WriteLine("{0}", soapEx.Message);
         throw;
     }
     return(availableServices);
 }
 /// <summary>
 /// Book Shipment Method
 /// </summary>
 /// <param name="shipments"></param>
 /// <returns></returns>
 private static ShipmentReturnType[] BookShipmentsMethod(String[] shipments)
 {
     ShipmentReturnType[] BookingResult = null;
     Service = GetAuthoriseService();
     try
     {
         // Call the GetDomesticServices soap service
         BookingResult = Service.BookShipments(shipments);
     }
     catch (Exception soapEx)
     {
         Console.WriteLine("{0}", soapEx.Message);
         throw;
     }
     return(BookingResult);
 }
        /// <summary>
        /// Gets the authorise service. Loads a XML configuration file, creates a
        /// Basic Auth credentials object and applies to the Service we want to use
        /// </summary>
        /// <returns>The authorise service.</returns>
        private static ShippingService GetAuthoriseService()
        {
            // Set up some credentials
            NetworkCredential netCredential = new NetworkCredential(apiuser, apikey);

            // Create the service of type Shipping service
            Service = new ShippingService
            {
                RequestEncoding = System.Text.Encoding.UTF8
            };
            Uri          uri         = new Uri(Service.Url);
            ICredentials credentials = netCredential.GetCredential(uri, "Basic");

            // Apply the credentials to the service
            Service.Credentials = credentials;
            return(Service);
        }
        /// <summary>
        /// Add a Shipment Method
        /// </summary>
        /// <param name="shipment"></param>
        /// <returns></returns>
        private static String AddShipmentMethod(ShipmentRequestType shipment)
        {
            String ShipmentID = null;

            Service = GetAuthoriseService();
            try
            {
                // Call the GetDomesticServices soap service
                Console.WriteLine(shipment.ServiceID);
                ShipmentID = Service.AddShipment(shipment);
            }
            catch (Exception soapEx)
            {
                Console.WriteLine("{0}", soapEx.Message);
                throw;
            }
            return(ShipmentID);
        }
        static async Task Main()
        {
            Console.Title = serviceName;

            using (var service = new ShippingService())
            {
                if (ServiceHelper.IsService())
                {
                    Run(service);
                    return;
                }
                await service.AsyncOnStart();

                Console.WriteLine("Endpoint started. Press any key to exit");
                Console.ReadKey();
                await service.AsyncOnStop();
            }
        }