且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

ASP.NET Core使用WCF客户端发出SOAP API请求时,如何向请求中添加Cookie标头?

更新时间:2023-09-10 11:13:58

通常,我们使用 HttpRequestMessageProperty 添加自定义HTTP标头.请参考下面的代码.

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

结果.

WebOperationContext是OperationContext的便利包装.目前,它尚未在Aspnet Core中实现.
https://github.com/dotnet/wcf/issues/2686
随时让我知道是否有什么可以帮助您的.

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.