1

我有一个非常简单的 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>

我将不胜感激一些指示,或朝着正确的方向轻推。

4

3 回答 3

6

好吧,您的服务使用 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>

如果您愿意,您也可以这样做(如果您关闭了安全性和 wsHttpBinding 提供的所有其他更高级的功能,那么使用 wsHttpBinding 与 basicHttpBinding 相比没有任何好处)<basicHttpBinding><wsHttpBinding>

还有一个非常好的博客文章系列,从五个不同的典型场景的角度讨论 WCF 安全的基础知识 - 非常棒!

马克

于 2009-08-05T14:49:57.520 回答
2

在配置 WCF 时,它可能是一个真正的痛苦。看看WCFSecurity,它为不同的配置环境提供了很好的工作示例。

于 2009-08-05T14:44:50.413 回答
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 示例

于 2009-08-05T14:56:46.447 回答