【问题标题】:Problems with WCF authenicationWCF 身份验证问题
【发布时间】:2010-11-17 01:11:38
【问题描述】:

我有一个非常简单的 WCF 服务,我想公开它。我创建了服务并将其设置在我们的服务器上,没有太多麻烦。问题是我们可以在我们的私有网络中使用该服务,但是当我们尝试从网络外部使用它时,会抛出以下错误:

安全支持提供程序接口 (SSPI) 协商失败。

我做了一些研究,听起来 WCF 默认使用 Windows 身份验证。我想将其更改为不使用身份验证,但我不完全确定如何。这是我的配置现在的样子。

<system.serviceModel>
    <services>
        <service behaviorConfiguration="XX.ZZ.WebService.MyServiceBehavior"
         name="XX.ZZ.WebService.MyService">
            <endpoint  address="" binding="wsHttpBinding" contract="XX.ZZ.WebService.IMyService">
            </endpoint>
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        </service>
    </services>
    <behaviors>
        <serviceBehaviors>
            <behavior name="XX.ZZ.WebService.MyServiceBehavior">
                <serviceMetadata httpGetEnabled="true" />
                <serviceDebug includeExceptionDetailInFaults="true" />
            </behavior>
        </serviceBehaviors>
    </behaviors>
</system.serviceModel>

我会很感激一些指示,或朝着正确的方向轻推。

【问题讨论】:

    标签: .net wcf exception-handling wcf-security wcf-binding


    【解决方案1】:

    好吧,您的服务使用 wsHttpBinding,默认情况下需要 Windows 用户凭据 - 您的外部用户显然不会拥有这些凭据。默认情况下(如您所说)使用 Windows 凭据的不是 WCF 本身,而是这个特定的绑定 (wsHttpBinding) - 其他人可能默认使用其他设置。

    你有几个选择:

    • 将 wsHttpBinding(相当“重量级”)配置为完全不使用安全性,或者使用调用者必须提供的用户名/密码安全性
    • 改用没有安全性的 basicHttpBinding(基本上就是 ASMX 模型)

    要完全关闭 wsHttpBinding 的安全性,请将其包含在您的配置中:

    <bindings>
      <wsHttpBinding>
        <binding name="NoSecurity">
          <security mode="None" />
        </binding>
      </wsHttpBinding>
    </bindings>
    

    然后配置您的端点以使用该绑定配置:

    <system.serviceModel>
        <services>
            <service name="XX.ZZ.WebService.MyService"
                     behaviorConfiguration="XX.ZZ.WebService.MyServiceBehavior">
               <endpoint address="" 
                         binding="wsHttpBinding" 
                         bindingConfiguration="NoSecurity" 
                         contract="XX.ZZ.WebService.IMyService">
                </endpoint>
                <endpoint address="mex" 
                          binding="mexHttpBinding" 
                          contract="IMetadataExchange" />
            </service>
        </services>
    

    如果您愿意,您可以使用 &lt;basicHttpBinding&gt; 而不是 &lt;wsHttpBinding&gt; 执行相同的操作(如果您关闭了安全性和 wsHttpBinding 提供的所有其他更高级的功能,那么使用 wsHttpBinding 与 basicHttpBinding 相比没有任何好处)。

    还有一个非常棒的blog post series,从五种不同的典型场景的角度讨论了 WCF 安全的基础知识 - 精彩阅读!

    马克

    【讨论】:

    【解决方案2】:

    这为您提供了无需身份验证的传输级安全性:

    <configuration>  <system.serviceModel>
        <services>
          <service 
              name="Microsoft.ServiceModel.Samples.CalculatorService"
              behaviorConfiguration="CalculatorServiceBehavior">
            <endpoint address=""
                      binding="wsHttpBinding"
                      bindingConfiguration="Binding1" 
                      contract="Microsoft.ServiceModel.Samples.ICalculator" />
          </service>
        </services>
        <bindings>
          <wsHttpBinding>
            <binding name="Binding1">
              <security mode="Transport">
                <transport clientCredentialType="None"/>
              </security>
            </binding>
          </wsHttpBinding>
        </bindings>
        <behaviors>
          <serviceBehaviors>
            <behavior name="CalculatorServiceBehavior">
              <serviceDebug includeExceptionDetailInFaults="False" />
            </behavior>
          </serviceBehaviors>
        </behaviors>  </system.serviceModel>
    </configuration>
    

    对于其他情况,我会看看Microsoft WCF samples。

    【讨论】:

    • 你能告诉我你是如何在没有证书的情况下实现传输安全的吗?这个答案没有意义。
    【解决方案3】:

    在配置 WCF 时可能会非常痛苦。看看WCFSecurity,它为不同的配置环境提供了很好的工作示例。

    【讨论】:

    • 查看我在回答中提到的那些博客文章——它们真的很有帮助,并且使 WCF 安全性就像选择这五个场景之一一样简单——真的! :-)
    • 博客文章还可以,但它们仅涵盖基本情况。 WCF 安全指南更加全面,涵盖的主题更加深入。
    • 嗯,重点是:这些博客文章涵盖了基本的五个场景,可能涵盖了您 90% 的用例。 WCF 安全指南涵盖了所有可能的功能组合——但您真的需要这些吗?由于它们涵盖了所有内容,因此您可能会淹没其中的大量信息.....
    猜你喜欢
    • 1970-01-01
    • 2011-11-27
    • 2011-10-25
    • 2016-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多