使用 WCF 的 Http 请求中缺少授权标头 [英] Authorization Header is missing in Http request using WCF

查看:22
本文介绍了使用 WCF 的 Http 请求中缺少授权标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 WCF 访问 Web 服务.使用 WSHttpBinding,安全模式设置为传输 (https),​​客户端凭据类型为基本.当我尝试使用代理访问服务时,收到 401 未经授权的异常.

I am accessing a web service using WCF. Using WSHttpBinding, Security mode is set Transport (https) and client credential type is Basic. When I try to access the service using the proxy, getting an 401 unauthorized exception.

这里是绑定

var binding = new WSHttpBinding()
        {
            UseDefaultWebProxy = true,
            Security =
            {
                Mode = SecurityMode.Transport,
                Transport =
                {
                    ClientCredentialType = HttpClientCredentialType.Basic,
                },
            }
        };

这里是服务调用

var client = new InternetClient(binding, new EndpointAddress("httpsurl"));

        client.ClientCredentials.UserName.UserName = "username";
        client.ClientCredentials.UserName.Password = "password";
        client.ProcessMessage("somevalue");

当使用 Http Analyzer 查看 Http 标头时连接头

When looked into Http headers using Http Analyzer CONNECT HEADER

(请求行):CONNECT somehost.com:443 HTTP/1.1
主持人:somehost.com
代理连接:保持活动

(Request-Line):CONNECT somehost.com:443 HTTP/1.1
Host:somehost.com
Proxy-Connection:Keep-Alive

帖子标题

(请求行):POST/Company/1.0 HTTP/1.1
内容类型:应用程序/soap+xml;字符集=utf-8
VsDebuggerCausalityData:uIDPo+voStemjalOv5LtRotFQ7UAAAAAUKLJpa755k6oRwto14BnuE2PDtYKxr9LhfqXFSOo8pEACQAA
主持人:somehost.com
内容长度:898
期望:100-继续
连接:保持活动状态

(Request-Line):POST /Company/1.0 HTTP/1.1
Content-Type:application/soap+xml; charset=utf-8
VsDebuggerCausalityData:uIDPo+voStemjalOv5LtRotFQ7UAAAAAUKLJpa755k6oRwto14BnuE2PDtYKxr9LhfqXFSOo8pEACQAA
Host:somehost.com
Content-Length:898
Expect:100-continue
Connection:Keep-Alive

如果您看到标头授权标头丢失

If you see the header Authorization header is missing

现在我的问题是为什么 WCF 调用缺少授权标头?我错过了什么吗?.请询问您是否需要更多信息

Now my question is why WCF call missing the Authorization header? Am I missing something? . Please ask if you need more information

推荐答案

其实这个问题我错了.在运行 HTTP 分析器时,我确实看到了不同的行为.在 Http anaylzer 运行时,我的应用程序在收到 401 响应后崩溃.当 Http 分析器应用程序关闭时,上述代码按预期工作.

Actually, I was wrong about this question. I did see different behaviour when running HTTP analyzer. While Http anaylzer running, my application crashed after receiving 401 response. When Http analyzer application closed, the above code worked as expected.

这篇关于使用 WCF 的 Http 请求中缺少授权标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆