Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send web header collection

Tags:

c#

wcf

How to send web header collection from rest Service to remoting service? I have tried to send web headers using below code but its not working.

System.Net.WebRequest request = base.GetWebRequest(uri);
request.Headers.Add("myheader", "myheader_value");
like image 776
Vijay Tanavade Avatar asked May 26 '26 16:05

Vijay Tanavade


1 Answers

You can try the below sample

public RemotingServiceClient serviceClient = new RemotingServiceClient();
public void Demo()
{
    using (OperationContextScope scope = new  OperationContextScope(serviceClient.InnerChannel))
    {
        MessageHeader<string> header = new MessageHeader<string>("HeaderValue1");
        var v1 = header.GetUntypedHeader("HeaderName1", "RemotingService");

        OperationContext.Current.OutgoingMessageHeaders.Add(v1);

        header = new MessageHeader<string>("HeaderValue2");
        var v2 = header.GetUntypedHeader("HeaderName2", "RemotingService");

        OperationContext.Current.OutgoingMessageHeaders.Add(v2);

        //IMP: To send headers make sure to call service in this block only.
        //Keep unique uri name "RemotingService"
        return serviceClient.MyRemotingServiceCall();
    }
}

It's working for me as expected

like image 57
Haripal Wagh Avatar answered May 28 '26 05:05

Haripal Wagh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!