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

∥☆過路亽.° 提交于 2021-01-28 11:41:00

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/59257689/asp-net-core-making-soap-api-request-with-wcf-client-how-to-add-a-cookie-header

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!