Pet*_*ter 2 api wcf soap session-cookies asp.net-core
所以我目前正在使用 WCF 生成的代码“客户端对象”向服务发出 SOAP API 请求,我想知道如何将 Cookie 标头设置为请求?
一般来说,我们通过使用添加自定义 HTTP 标头HttpRequestMessageProperty。请参考下面的代码。
ServiceReference1.ServiceClient client = new ServiceReference1.ServiceClient();\ntry\n{\n using (OperationContextScope ocs=new OperationContextScope(client.InnerChannel))\n {\n var requestProp = new HttpRequestMessageProperty();\n requestProp.Headers["myhttpheader"] = "Boom";\n OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = requestProp;\n var result = client.SayHelloAsync();\n Console.WriteLine(result.Result);\n }\nRun Code Online (Sandbox Code Playgroud)\n\n结果。
\n
\nWebOperationContext 是 OperationContext 的便捷包装器。目前,它还没有在Aspnet Core中实现。
\n https://github.com/dotnet/wcf/issues/2686
\n如果有什么我可以帮忙的,请随时告诉我。
| 归档时间: |
|
| 查看次数: |
2722 次 |
| 最近记录: |