Adding HTTP request header to WCF request Adding HTTP request header to WCF request ajax ajax

Adding HTTP request header to WCF request


The simplest way to this is using WebOperationContext at the following way:

Service1Client serviceClient = new Service1Client();using (new System.ServiceModel.OperationContextScope((System.ServiceModel.IClientChannel)serviceClient.InnerChannel)){    System.ServiceModel.Web.WebOperationContext.Current.OutgoingRequest.Headers.Add("AdminGUID", "someGUID");    serviceClient.GetData();}

Taken from this post


Make a new WebRequest object of type HttpWebRequest. Set the header and get the response.

WebRequest req = HttpWebRequest.Create("myURL") as HttpWebRequest;req.Headers.Add("AdminGUID", "value");HttpWebResponse response = (HttpWebResponse)request.GetResponse();

for a more in depth example of webrequest, see this page