So I am currently working on making SOAP API request to a service with WCF generated code "Client object", I am wondering how to set the Cookie header to the request?
Asked
Active
Viewed 2,497 times
1 Answers
5
In general, we add the custom HTTP header by using HttpRequestMessageProperty. Please refer to the below code.
ServiceReference1.ServiceClient client = new ServiceReference1.ServiceClient();
try
{
using (OperationContextScope ocs=new OperationContextScope(client.InnerChannel))
{
var requestProp = new HttpRequestMessageProperty();
requestProp.Headers["myhttpheader"] = "Boom";
OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = requestProp;
var result = client.SayHelloAsync();
Console.WriteLine(result.Result);
}
Result.

WebOperationContext is a convenience wrapper around the OperationContext. At present, it hasn’t been implemented yet in the Aspnet Core.
https://github.com/dotnet/wcf/issues/2686
Feel free to let me know if there is anything I can help with.
Abraham Qian
- 7,117
- 1
- 8
- 22
-
super man, thanks, i was really struggling to make it work with .net core, this worked perfectly – Pankaj Singh May 02 '21 at 17:24
-
after a lot of struggle and search, this is the code that works and it also can be used with async/await. thanks a lot! – Alexander Sep 15 '21 at 10:43