api - ASP.NET Core 使用 WCF 客户端发出 SOAP API 请求如何向请求添加 Cookie header ?

标签 api wcf asp.net-core soap session-cookies

所以我目前正在使用 WCF 生成的代码“客户端对象”向服务发出 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);
    }

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

关于api - ASP.NET Core 使用 WCF 客户端发出 SOAP API 请求如何向请求添加 Cookie header ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59257689/

相关文章:

perl - 我在哪里可以找到一些简单的 Perl W3C Validator API 信息?

c# - .NET 外部通信

WCF 方法调用了两次

c# - 是否有 WCF Rest C# 客户端生成工具?

python - 如何使用 ElementTree 获取元素的完整 XML 或 HTML 内容?

java - Java 中是否有用于文本分析/挖掘的 API?

api - golang json 解码中的指针

asp.net-core - 为什么 `UseAuthentication` 必须放在 `UseRouting` 之后而不是之前?

c# - .Net core 脚手架 dbcontext 失败,无法加载类型 'System.IO.File'

c# - 使用 md5 哈希或文件长度进行文件比较?