This article demonstrates how to make a call from client to a REST based service with Header in Request
var binding = new WebHttpBinding();
binding.Security.Mode = WebHttpSecurityMode.Transport;
var cf = new WebChannelFactory<SERVICE_TYPE>(binding, new Uri(URL));
{
Console.WriteLine("{0}:Creating Channel", System.DateTime.Now.ToString("hh:mm:ss"));
var proxy = cf.CreateChannel();
using (new OperationContextScope((IClientChannel)proxy))
{
WebOperationContext.Current.OutgoingRequest.Headers.Add("Sample", "SamValue");
Console.WriteLine("{0}:Calling Method", System.DateTime.Now.ToString("hh:mm:ss"));
proxy.Method(Entity);
Console.WriteLine("{0}:Calling Completed in {1} Seconds", System.DateTime.Now.ToString("hh:mm:ss"), System.DateTime.Now.Subtract(le).TotalSeconds);
}
}
cf.Close();
Console.ReadLine();
var binding = new WebHttpBinding();
binding.Security.Mode = WebHttpSecurityMode.Transport;
var cf = new WebChannelFactory<SERVICE_TYPE>(binding, new Uri(URL));
{
Console.WriteLine("{0}:Creating Channel", System.DateTime.Now.ToString("hh:mm:ss"));
var proxy = cf.CreateChannel();
using (new OperationContextScope((IClientChannel)proxy))
{
WebOperationContext.Current.OutgoingRequest.Headers.Add("Sample", "SamValue");
Console.WriteLine("{0}:Calling Method", System.DateTime.Now.ToString("hh:mm:ss"));
proxy.Method(Entity);
Console.WriteLine("{0}:Calling Completed in {1} Seconds", System.DateTime.Now.ToString("hh:mm:ss"), System.DateTime.Now.Subtract(le).TotalSeconds);
}
}
cf.Close();
Console.ReadLine();
No comments:
Post a Comment