Adding HTTP request header to WCF request

后端 未结 2 1590
长发绾君心
长发绾君心 2021-02-14 13:40

I have a WCF service consume by both AJAX and C# application,
I need to send a parameter through the HTTP request header.

On my AJAX I have added the following and i

2条回答
  •  太阳男子
    2021-02-14 14:16

    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

提交回复
热议问题