ASP.NET 使用 WCF 客户端进行 SOAP API 请求的核心如何向请求添加 Cookie header?

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

所以我目前正在使用 WCF 生成的代码 "Client object" 向服务发出 SOAP API 请求,我想知道如何将 Cookie header 设置为请求?

一般情况下,我们使用 HttpRequestMessageProperty 添加自定义 HTTP header。请参考以下代码。

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);
    }

结果。

WebOperationContext 是 OperationContext 的便利包装器。目前还没有在Aspnet Core中实现。
https://github.com/dotnet/wcf/issues/2686
如果有什么我可以帮忙的,请随时告诉我。