Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Net;
- using System.Text;
- using System.Windows.Forms;
- using System.Threading.Tasks;
- namespace ConsoleApp1
- {
- class MiniHotelApi
- {
- private struct SCI_Document
- {
- public string ReservationNumber;
- public string DocType;
- public string DocValue;
- public string Description;
- }
- public static string cmdSend_Click()
- {
- string path = @"C:\inetpub\wwwroot\rambam\system\images\scannedImage1.jpg";
- List<SCI_Document> lstDocuments = new List<SCI_Document>();
- lstDocuments.Add(new SCI_Document()
- {
- Description = "Test Example",
- DocType = Path.GetExtension(path).Replace(".", ""),
- DocValue = EncodeImage(path),
- ReservationNumber = "007000301"
- });
- string AgentUser = "rambam"; //MiniHotel Rambam agent username
- string AgentPass = "bam*700"; //MiniHotel Rambam agent password
- string HotelID = "rambam"; //MiniHotel Rambam HotelID
- string Response = SendRequest(getXMLRequest(AgentUser, AgentPass, HotelID, lstDocuments)); //Send Request Using RamBam agent credentials
- return Response;
- //frmXML xmlResponseDialog = new frmXML(Response);
- // xmlResponseDialog.ShowDialog();
- // xmlResponseDialog.Dispose();
- } //Send Request Button
- public static string EncodeImage(string path)
- {
- string EncodedImage = "";
- System.Drawing.Image img = System.Drawing.Image.FromFile(path);
- try
- {
- EncodedImage = Convert.ToBase64String(ImageToByteArray(img));
- }
- catch (Exception ex)
- {
- }
- return EncodedImage;
- } //Encode Image Function
- public static byte[] ImageToByteArray(System.Drawing.Image imageIn)
- {
- MemoryStream ms = new MemoryStream();
- imageIn.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
- return ms.ToArray();
- } //Converts image to ByteArray
- /// <summary>
- /// send
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- #region "Server Functions"
- private static string SendRequest(string postdata)
- {
- HttpWebRequest s;
- UTF8Encoding enc;
- byte[] postdatabytes;
- string ServerURL = "http://sandbox.hotel-wiz.com/";
- if (ServerURL.EndsWith("/"))
- ServerURL = ServerURL.Substring(0, ServerURL.Length - 1);
- string FunctionURL = ServerURL + "/agents/ws/sci/sciMain.asmx/saveDocuments";
- s = (HttpWebRequest)WebRequest.Create(FunctionURL);
- enc = new System.Text.UTF8Encoding();
- postdatabytes = enc.GetBytes(postdata);
- s.Method = "POST";
- s.ContentType = "application/xml";
- s.ContentLength = postdatabytes.Length;
- using (var stream = s.GetRequestStream())
- {
- stream.Write(postdatabytes, 0, postdatabytes.Length);
- }
- var result = s.GetResponse();
- string responseStr = "";
- try
- {
- StreamReader reader = new StreamReader(result.GetResponseStream());
- responseStr = reader.ReadToEnd();
- reader.Close();
- }
- catch (Exception ex)
- {
- }
- return responseStr;
- } //POST function to send XML Request
- private static string getXMLRequest(string Username, string Password, string HotelId, List<SCI_Document> lstDocuments)
- {
- string strXML = "";
- strXML += "<?xml version='1.0' encoding='UTF-8'?>"; //Create XML Header
- strXML += "<Request>"; //Create 'Request' Node
- strXML += "<SCI name='sci_saveDocuments'>"; //Create 'SCI' Node
- strXML += "<Authentication username='" + Username + "' password='" + Password + "' />"; //Create 'Authentication' Node
- strXML += "<Hotel id='" + HotelId + "' />"; //Create 'Hotel' Node
- strXML += "<Documents>"; //Create 'Documents' Node
- foreach (SCI_Document d in lstDocuments) //Iterate throught Documents List
- strXML += "<Document rs_number='" + d.ReservationNumber //Create 'Document' Node
- + "' Doc_type='" + d.DocType
- + "' Doc_value='" + d.DocValue
- + "' Description='" + d.Description + "' />";
- strXML += "</Documents>"; //End of 'Documents' Node
- strXML += "</SCI>"; //End of 'SCI' Node
- strXML += "</Request>"; //End of 'Request' Node
- return strXML; //Return created XML Request
- } //Function that creates saveDocuments() XML Request
- #endregion
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement