Use this class to create an AuthenticationRequest for an operation to authenticate against CarRentalAgentService interface and obtain a TicketGrantingTicket.
For a list of all members of this type, see TicketGrantingTicketRequest Members.
System.Object
AuthenticationRequest
TicketGrantingTicketRequest
Public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread-safe.
The TicketGrantingTicketRequest is the first request you will have to create before calling any other methods from CarRentalAgentService.
This request contains an OperatorKey, which is the operator key you get when you sign an operator contract with Sunny Cars. This key is used to identify your records within the operator database at Sunny Cars. The OperatorKey must be set to create a valid request.
Furthermore, you can set the ImpersonationKey and ImpersonationContext values to initiate an impersonation. An impersonation is the method of operating on behalf of another operator or agency.
NoteThe impersonation functionality is only activated for those operators, which have contracted the impersonation with Sunny Cars. For each impersonation, Sunny Cars provides you an impersonation context (an encytpted context secret). Please refer to your operator documentation for further details.
This function requests a Ticket for OperatorKey = "369220" and prints the result to stdout and may be used as sample-application.
[C#]
static void Main(string[] args)
{
// the part before the '.' may differ due to the name you selected for the web-reference
CarRentalAgentService.CarRentalAgentService service;
service = new CarRentalAgentService.CarRentalAgentService();
// replace the url with the one, given by sunnycars
service.Url = "http://localhost/dev_sunnycars/CarRentalAgentService20/CarRentalAgentService.asmx";
CarRentalAgentService.TicketGrantingTicketRequest req_granting_ticket = new CarRentalAgentService.TicketGrantingTicketRequest();
// set sunnycars test operator
req_granting_ticket.OperatorKey = "369220";
// send request to get the GrantingTicket
CarRentalAgentService.TicketGrantingTicketResponse resp_granting_ticket;
resp_granting_ticket = service.GetTicketGrantingTicket(req_granting_ticket);
// GetTicketGrantingTicket returns successfully
if (resp_granting_ticket.Status.Code == CarRentalAgentService.StatusCode.Success)
{
// this is the password for sunnycars test operator
string passPhrase = "test0001";
///////////////////////////////////////////////////////////////////////////////////////////////////////
// decode and decrypt secret using .NET classes
// using System.Security.Cryptography;
// using System.IO;
// get the md5 hash of passPhrase as byte array
byte[] md5PassPhraseHash = null;
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
md5PassPhraseHash = md5.ComputeHash(Encoding.UTF8.GetBytes(passPhrase));
//decode the returned secret
byte[] decodedSecret = Convert.FromBase64String(resp_granting_ticket.TicketGrantingTicket.Secret);
// prepare TripleDESCryptoServiceProvider for decryption
TripleDESCryptoServiceProvider tdes_dec = new TripleDESCryptoServiceProvider();
tdes_dec.Key = md5PassPhraseHash;
byte[] cIV_dec = new byte[8];
Array.Copy(md5PassPhraseHash, cIV_dec, 8);
tdes_dec.IV = cIV_dec;
// decrypt secret
MemoryStream memstream_dec = new MemoryStream();
CryptoStream cs_dec = new CryptoStream(memstream_dec, tdes_dec.CreateDecryptor(), CryptoStreamMode.Write);
cs_dec.Write(decodedSecret, 0, decodedSecret.Length);
cs_dec.FlushFinalBlock();
cs_dec.Close();
byte[] decryptedSecret = memstream_dec.ToArray();
// convert secret to int64
Int64 secret = Convert.ToInt64(Encoding.UTF8.GetString(decryptedSecret));
// decode and decrypt secret using .NET classes
// using System.Security.Cryptography;
// using System.IO;
///////////////////////////////////////////////////////////////////////////////////////////////////////
// increment secret
secret = secret + 1;
///////////////////////////////////////////////////////////////////////////////////////////////////////
// encode and encrypt secret using .NET classes
// using System.Security.Cryptography;
// using System.IO;
// encode the incremented secret
byte[] encodedSecret = Encoding.UTF8.GetBytes(Convert.ToString(secret));
// prepare TripleDESCryptoServiceProvider for encryption
TripleDESCryptoServiceProvider tdes_enc = new TripleDESCryptoServiceProvider();
tdes_enc.Key = md5PassPhraseHash;
byte[] cIV_enc = new byte[8];
Array.Copy(md5PassPhraseHash, cIV_enc, 8);
tdes_enc.IV = cIV_enc;
// encrypt secret
MemoryStream memstream = new MemoryStream();
CryptoStream cs = new CryptoStream(memstream, tdes_enc.CreateEncryptor(), CryptoStreamMode.Write);
cs.Write(encodedSecret, 0, encodedSecret.Length);
cs.FlushFinalBlock();
cs.Close();
byte[] encryptedSecret = memstream.ToArray();
string secret_encrypted = Convert.ToBase64String(encryptedSecret);
// encode and encrypt secret using .NET classes
// using System.Security.Cryptography;
// using System.IO;
///////////////////////////////////////////////////////////////////////////////////////////////////////
// call GetTicket to get the Ticket for use with each CarRentalAgentService - webmethod
CarRentalAgentService.TicketRequest req_ticket = new CarRentalAgentService.TicketRequest();
// BookingModule-Key empty means use the default, please insert the key you got from sunnycars if any
req_ticket.BookingModuleKey = "";
req_ticket.TicketGrantingTicket = resp_granting_ticket.TicketGrantingTicket;
req_ticket.TicketGrantingTicket.Secret = secret_encrypted;
// send request to get the Ticket
CarRentalAgentService.TicketResponse resp_ticket;
resp_ticket = service.GetTicket(req_ticket);
// GetTicket returns successfully
if (resp_ticket.Status.Code == CarRentalAgentService.StatusCode.Success)
{
// print the result to stdout
Console.WriteLine("Authorisation successful!");
Console.WriteLine("Ticket.Token = " + resp_ticket.Ticket.Token);
Console.WriteLine("Ticket.Timestamp = " + resp_ticket.Ticket.Timestamp);
Console.WriteLine("Ticket.Expires = " + resp_ticket.Ticket.Expires);
Console.ReadKey(false);
}
}
}
Namespace: SunnyCars.Schema.Osi.WsReservation.V4
Assembly: Sunnycars.Schema.Osi.WsReservation.V4 (in Sunnycars.Schema.Osi.WsReservation.V4.dll)
TicketGrantingTicketRequest Members | SunnyCars.Schema.Osi.WsReservation.V4 Namespace | TicketGrantingTicket | TicketGrantingTicketResponse