使用 HttpRequestMessageProperty 和 OperationContextScope 的 WCF HTTP 标头

发布于 2024-12-01 01:29:53 字数 965 浏览 1 评论 0 原文

我意识到这是一个被反复问到的问题,但我找不到可以查看的“陷阱”列表。

我正在编写一个 WCF 客户端,该客户端将使用 SAP Web 服务,在 web.config 中使用 customBinding,将allowCookies 设置为 false 并启用对可靠会话的支持。我将 HTTP 标头设置如下:

var authCookie = new System.Net.Cookie();
var wcfClient = new SomeWcfClient();
using (var context = new OperationContextScope(wcfClient.InnerChannel))
{
    var cookies = new CookieContainer();
    cookies.Add(authCookie);
    var endPoint = new EndpointAddress("http://someDomain.test/");

    var httpRequest = new System.ServiceModel.Channels.HttpRequestMessageProperty();
    OperationContext.Current.OutgoingMessageProperties.Add(System.ServiceModel.Channels.HttpRequestMessageProperty.Name, httpRequest);
    httpRequest.Headers.Add(HttpRequestHeader.Cookie, cookies.GetCookieHeader(endPoint.Uri));

    wcfClient.PerformOperation();
}

当我使用 Fiddler 时,我的 HTTP 标头不会出现。我也尝试过创建虚拟 Referer 和 User-Agent 标头,认为我的 cookie 标头可能发生了一些特定的情况,但即使是其他标头也没有出现。有什么想法吗?接下来我该看哪里?

I realize this is a question that's been asked time and again, but I can't find a list of "gotchas" that I can take a look at.

I'm writing a WCF client that will consume an SAP web service, using a customBinding in my web.config with allowCookies set to false and support for reliable sessions enabled. I'm setting my HTTP headers as follows:

var authCookie = new System.Net.Cookie();
var wcfClient = new SomeWcfClient();
using (var context = new OperationContextScope(wcfClient.InnerChannel))
{
    var cookies = new CookieContainer();
    cookies.Add(authCookie);
    var endPoint = new EndpointAddress("http://someDomain.test/");

    var httpRequest = new System.ServiceModel.Channels.HttpRequestMessageProperty();
    OperationContext.Current.OutgoingMessageProperties.Add(System.ServiceModel.Channels.HttpRequestMessageProperty.Name, httpRequest);
    httpRequest.Headers.Add(HttpRequestHeader.Cookie, cookies.GetCookieHeader(endPoint.Uri));

    wcfClient.PerformOperation();
}

When I use Fiddler, my HTTP header does not come across. I've tried creating dummy Referer and User-Agent headers, too, thinking that maybe something specific was happening with my cookie header, but even those other headers did not come across. Any thoughts? Where should I look next?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

剩一世无双 2024-12-08 01:29:53
樱桃奶球 2024-12-08 01:29:53

所以,这个问题与我们的预期有很大不同。我仍在尝试寻找解决方案,但至少我知道根本原因:

我无法发送 HTTP cookie 来验证我的请求;我们的 SAP 服务使用 MYSAPSSO2 令牌(HTTP cookie)进行身份验证。当尝试使用 WCF 连接到启用可靠会话的 SAP Web 服务时,我们的 cookie 不会预先发送。

我们正在寻找一种方法来构建可以使用 HTTP cookie 的自定义身份验证提供程序。

So, this issue was a lot different than we were expecting. I am still trying to find a fix, but at least I know root cause:

I am unable to send HTTP cookies to authenticate my requests; our SAP services use a MYSAPSSO2 token (HTTP cookie) for authentication. When trying to use WCF to connect to a Reliable Session-enabled SAP web service, our cookies don't get sent up front.

We are looking for a way to build a custom authentication provider that can use HTTP cookies.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文