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

查看:412
本文介绍了使用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.

这是Binding

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标头
CONNECT HEADER

When looked into Http headers using Http Analyzer CONNECT HEADER

(请求行):CONNECT somehost.com:443 HTTP / 1.1

主机:somehost.com

代理连接:Keep-Alive < br>

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

POST HEADER

POST HEADER

(请求行):POST /Company/1.0 HTTP / 1.1

Content-Type:application / soap + xml; charset = utf-8

VsDebuggerCausalityData:uIDPo + voStemjalOv5LtRotFQ7UAAAAAUKLJpa755k6oRwto14BnuE2PDtYKxr9LhfqXFSOo8pEACQAA

主持人:somehost.com

内容长度:898

期望: 100-continue

连接:Keep-Alive

(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调用缺少Authorization标头?我错过了什么吗? 。请询问您是否需要更多信息

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天全站免登陆