Reputation: 33
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");
Upvotes: 3
Views: 351
Reputation: 572
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
Upvotes: 2