ASP.NET Core 使用 WCF 客户端发出 SOAP API 请求如何向请求添加 Cookie 标头? [英] ASP.NET Core making SOAP API request with WCF client how to add a Cookie header to the request?
问题描述
所以我目前正在使用 WCF 生成的代码客户端对象"向服务发出 SOAP API 请求,我想知道如何将 Cookie 标头设置为请求?
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?
推荐答案
一般来说,我们使用 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.
这篇关于ASP.NET Core 使用 WCF 客户端发出 SOAP API 请求如何向请求添加 Cookie 标头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!