Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET Core making SOAP API request with WCF client how to add a Cookie header to the request?

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?

like image 393
Peter Avatar asked Dec 05 '25 03:12

Peter


1 Answers

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.
enter image description here
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.

like image 199
Abraham Qian Avatar answered Dec 07 '25 19:12

Abraham Qian



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!