We have intended this section to provide some code samples and the possible ways this web service can be consumed or used to make client’s integration process faster.
Please go through the below search request
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:hot="http://TekTravel/HotelBookingApi">
<soap:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
<hot:Credentials UserName="testuser" Password="testpwd">
</hot:Credentials>
<!-- You need to change the Soap Action as per the method call -->
<!-- below wsa:Action and wsa:To nodes are required -->
<wsa:Action>http://TekTravel/HotelBookingApi/HotelSearch</wsa:Action>
<wsa:To>http://api.tbotechnology.in/HotelAPI_V7/HotelService.svc</wsa:To>
</soap:Header>
<soap:Body>
<hot:HotelSearchRequest>
<hot:CheckInDate>2014-03-26T00:00:00.000+05:00</hot:CheckInDate>
<hot:CheckOutDate>2014-03-27T00:00:00.000+05:00</hot:CheckOutDate>
<hot:CountryName>United States</hot:CountryName>
<hot:CityName>New York</hot:CityName>
<hot:CityId>28985</hot:CityId>
<hot:NoOfRooms>1</hot:NoOfRooms>
<hot:GuestNationality>AE</hot:GuestNationality>
<hot:RoomGuests>
<hot:RoomGuest AdultCount="1" ChildCount="0">
</hot:RoomGuest>
</hot:RoomGuests>
<hot:ResultCount>0</hot:ResultCount>
<hot:Filters>
<hot:HotelName></hot:HotelName>
<hot:StarRating>All</hot:StarRating>
<hot:OrderBy>PriceAsc</hot:OrderBy>
</hot:Filters>
</hot:HotelSearchRequest>
</soap:Body>
</soap:Envelope>
bool compressionRequested = true;
string xml = File.ReadAllText(@"D:\searchReqAPI7.xml"); /* Load search request XML */
HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://api.tbotechnology.in/HotelAPI_V7/HotelService.svc");
req.Method = "POST";
req.ContentType = "application/soap+xml; charset=UTF-8";
if (compressionRequested)
{
/* required if you want to receive compressed response */
req.Headers.Add("Accept-Encoding", "gzip, deflate");
}
StreamWriter stOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);
stOut.Write(xml);
stOut.Close();
string respXml; /* will contain response from api in string form */
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
if (resp.ContentEncoding == "gzip")
{
/* You can put your code to implement decompression */
Stream st = resp.GetResponseStream();
if (resp.ContentEncoding.ToLower().Contains("gzip"))
st = new System.IO.Compression.GZipStream(st, System.IO.Compression.CompressionMode.Decompress);
else if (resp.ContentEncoding.ToLower().Contains("deflate"))
st = new System.IO.Compression.DeflateStream(st, System.IO.Compression.CompressionMode.Decompress);
StreamReader stIn = new StreamReader(st, Encoding.Default);
respXml = stIn.ReadToEnd();
stIn.Close();
}
else
{
StreamReader stIn = new StreamReader(resp.GetResponseStream());
respXml = stIn.ReadToEnd();
stIn.Close();
}
Another way of consuming this web service, please check and follow the below steps.
Step 1 : Adding Service Reference
Add Service reference in project of this web service (The URL will be like "http://api.tbotechnology.in/HotelAPI_V7/HotelService.svc") and name it as 'hotelServiceRef'.
Step 2 : Include hotelServiceRef and System.ServiceModel
using hotelServiceRef;
using System.ServiceModel;
Step 3 : Connecting and Using Web Service
Below Sample code can be put and used in a method
ChannelFactory<IHotelService> factory = new ChannelFactory<IHotelService>("WSHttpBinding_IHotelService", new EndpointAddress("http://api.tbotechnology.in/HotelAPI_V7/HotelService.svc"));
IHotelService proxy = factory.CreateChannel();
HotelBookingDetailRequest req = new HotelBookingDetailRequest(); /* request object*/
req.Credentials = new AuthenticationData();
req.Credentials.UserName = "testuser";
req.Credentials.Password = "testpwd";
req.BookingId = 1729;
HotelBookingDetailResponse resp = new HotelBookingDetailResponse(); /* response object */
resp = proxy.HotelBookingDetail(req); /* Web service method call*/