vinSUITE
Web Services v2.00 API Documentation
Loading...
Searching...
No Matches
Program.cs

Example of vinSUITE API AddOrder and GetOrders calls written in C#

using System;
using System.Configuration;
using System.Xml.Serialization;
// Web reference to eWinery Solutions Webservices 2.0
using WebserviceSamples.localhost;
namespace WebserviceSamples
{
class Program
{
static void Main(string[] args)
{
using (EWSWebServices webServices = new EWSWebServices())
{
// Setup authentication credentials for a web service call
// Authentication credentials are stored in app.config file.
AddOrderRequest addOrderRequest = new AddOrderRequest();
addOrderRequest.Username = ConfigurationManager.AppSettings["Username"];
addOrderRequest.Password = ConfigurationManager.AppSettings["Password"];
addOrderRequest.PartnerKeyID = new Guid(ConfigurationManager.AppSettings["PartnerKeyID"]);
// Setup order details
OrderAdd orderAdd = new OrderAdd();
addOrderRequest.Order = orderAdd;
orderAdd.ShippingFirstName = "Sample";
orderAdd.ShippingLastName = "Order";
orderAdd.BillingEmail = "sample@order";
orderAdd.SubTotal = 50;
orderAdd.Taxes = 10;
orderAdd.Total = 60;
// Create a single order item and attach to an order
OrderItemAdd orderItemAdd = new OrderItemAdd();
orderAdd.OrderItems = new OrderItemAdd[1];
orderAdd.OrderItems[0] = orderItemAdd;
orderItemAdd.SKU = "SampleProduct";
orderItemAdd.Quantity = 1;
orderItemAdd.BottleCount = 1;
orderItemAdd.Name = "Sample Product";
orderItemAdd.Price = 50;
// Call AddOrder and save response
AddOrderResponse addOrderResponse = webServices.AddOrder(addOrderRequest);
// Call GetOrders and filter out the order that was just created
if (addOrderResponse.IsSuccessful)
{
// Setup authentication credentials for a web service call
// Authentication credentials are stored in app.config file.
GetOrdersRequest getOrdersRequest = new GetOrdersRequest();
getOrdersRequest.Username = ConfigurationManager.AppSettings["Username"];
getOrdersRequest.Password = ConfigurationManager.AppSettings["Password"];
getOrdersRequest.PartnerKeyID = new Guid(ConfigurationManager.AppSettings["PartnerKeyID"]);
// Set GetOrders filters
getOrdersRequest.OrderID = addOrderResponse.OrderID;
// Call GetOrders and save response
GetOrdersResponse getOrdersResponse = webServices.GetOrders(getOrdersRequest);
// Display GetOrders response
SerializeAndDisplay(getOrdersResponse);
}
}
Console.ReadLine();
}
// Serialize and display object in terminal
private static void SerializeAndDisplay(Object response)
{
Type objType = response.GetType();
XmlSerializer serializer = new XmlSerializer(objType);
Console.WriteLine("======= XML OBJECT =======");
serializer.Serialize(Console.Out, response);
}
}
}