加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

如何使用Windows凭据将WCF服务重定向到HTTPS端点

发布时间:2020-12-14 02:22:15 所属栏目:Windows 来源:网络整理
导读:以下是我要处理的情况: 我们有一个WCF客户端,它与http端点和https端点一起使用,但在从http重定向(302)到https时却没有.我们有一个F5负载均衡器,它正在执行重定向和SSL功能,但据我所知,它没有对请求做任何意外的事情.重定向似乎是WCF在执行重定向后不希望提
以下是我要处理的情况:

我们有一个WCF客户端,它与http端点和https端点一起使用,但在从http重定向(302)到https时却没有.我们有一个F5负载均衡器,它正在执行重定向和SSL功能,但据我所知,它没有对请求做任何意外的事情.重定向似乎是WCF在执行重定向后不希望提供Windows Kerberos身份验证信息的罪魁祸首.

成功呼叫的顺序(即没有重定向的http)如下所示:

>客户端 – 使用http方案发送服务的POST请求
>服务器 – 未经授权的401响应
>客户端 – 发送授权协商POST
>服务器 – 以100继续响应
>客户端 – 发送soap数据并成功完成

当呼叫被重定向并失败时,它会像这样:

>客户端 – 使用http方案发送服务的POST请求
>服务器 – 返回302,重定向到同一地址的https方案
>客户端 – 为https地址发送GET(我无法弄清楚为什么这是GET而不是POST)
>服务器 – 未经授权的401响应
>客户端 – 抛出异常“HTTP请求未经授权,客户端身份验证方案’协商’.从服务器收到的身份验证标头是’Negotiate,NTLM’.”

它类似于this problem但不完全相同(虽然它确实引用了“破坏WCF协议”,但我没有真正的答案,我可以找到文档).如果我们关闭F5重定向规则http和https流量工作正常. WCF真的不能处理这个简单的重定向吗?有关此漏洞的解决方法或任何文档吗?

客户端配置(请注意,使用https进行测试时,我将TransportCredentialOnly更改为Transport):

<client>
        <endpoint address="http://fooserver/MyService.svc/" binding="basicHttpBinding" bindingConfiguration="clientBinding" contract="Contracts.IMyService" />
</client>
<bindings>
<basicHttpBinding>
    <binding name="clientBinding">
        <security mode="TransportCredentialOnly">
            <transport clientCredentialType="Windows" proxyCredentialType="Windows" />
        </security>
    </binding>
</basicHttpBinding>

服务器配置如下所示:

<system.serviceModel>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
    <services>
        <service behaviorConfiguration="MyServiceBehavior" name="MyService">
            <endpoint address="" binding="basicHttpBinding" bindingConfiguration="securedBinding" contract="Contracts.IMyService">
            </endpoint>
        </service>
    </services>
    <bindings>
        <basicHttpBinding>
            <binding name="securedBinding">
                <security mode="TransportCredentialOnly">
                    <transport clientCredentialType="Windows" proxyCredentialType="Windows"/>
                </security>
            </binding>
        </basicHttpBinding>
    </bindings>
    <behaviors>
        <serviceBehaviors>
            <behavior name="MyServiceBehavior">
                <serviceMetadata httpGetEnabled="true"/>
                <serviceDebug includeExceptionDetailInFaults="true"/>
                <useRequestHeadersForMetadataAddress>
                    <defaultPorts>
                        <add scheme="http" port="80" />
                        <add scheme="https" port="443" />
                    </defaultPorts>
                </useRequestHeadersForMetadataAddress>
            </behavior>
        </serviceBehaviors>
    </behaviors>
</system.serviceModel>

解决方法

I can’t figure out why this is a GET and not a POST

这是你的问题的原因.收到对POST的302响应后,客户端需要获取新URL的行为.请参阅http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html中的以下内容

If the 302 status code is received in response to a request other than GET or HEAD,the user agent MUST NOT automatically redirect the request unless it can be confirmed by the user,since this might change the conditions under which the request was issued.

此外,以下SO帖子有一些很好的信息:Response.Redirect with POST instead of Get?

所以WCF通过在302重定向后拒绝重新POST来做它应该做的事情.不幸的是,我不知道如何解决你的问题,除了第一次正确指定协议以避免302.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读