2010-11-29 90 views
2

我有两个网站托管在同一个IIS服务器上。 SiteA包含需要由SiteB访问的WCF服务,以及在域中进行身份验证的任何其他服务。配置WCF安全(wsHttpBinding)

服务配置了的wsHttpBinding,因此我相信,在默认情况下使用Windows的安全性。现在我可以从本地机器上运行的控制台应用程序调用服务,也可以从运行在默认Visual Studio Web服务器中的Web应用程序调用服务,所以我认为该认证正在工作。

但是,当SiteB尝试访问服务时,它会失败,并显示以下错误: 调用者未被服务验证。

网站B在同一台机器不是站点A上运行,所以我不明白为什么它不能进行身份验证。 SiteB使用表单身份验证,并将匿名访问映射到域用户。

下面是配置位:

站点A(服务):

<system.serviceModel> 
     <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /> 
     <services> 
      <service behaviorConfiguration="wcfServiceBehaviour" name="MyService"> 
       <endpoint address="" binding="wsHttpBinding" contract="IServiceContract" /> 
       <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
      </service> 
     </services> 
     <behaviors> 
      <serviceBehaviors> 
       <behavior name="wcfServiceBehaviour"> 
        <serviceMetadata httpGetEnabled="true" /> 
        <serviceDebug includeExceptionDetailInFaults="true" /> 
       </behavior> 
      </serviceBehaviors> 
     </behaviors> 
    </system.serviceModel> 

网站B(客户端):

<system.serviceModel> 
    <client> 
     <endpoint address="http://xxxxx/Services/xxService.svc" 
       binding="wsHttpBinding" 
       contract="IServiceContract" /> 
    </client> 
</system.serviceModel> 
+0

泽维尔嗨,我的道歉,我错了。我显然错过了这一点。 – Aliostad 2010-11-29 09:23:56

回答

1

你是正确的 - 在WCF配置的wsHttpBinding将默认使用Windows身份验证。

这里有一个建议 - WCF - changing endpoint address results in securityexception - 的身份块将不会使用Windows身份验证工作 - 尝试将其移除。

+0

感谢您的提示。我已经删除了身份代码块,但身份验证仍然不起作用。我编辑了我的问题以反映这些变化。 – 2010-11-29 03:03:59

+1

你有没有考虑使用NetNamedPipeBinding而不是wsHttpBinding?这种绑定对于同一机器的处理是安全和优化的。如果您仍然需要提供外部访问,则可以保留wsHttpBinding(假设它适用于外部用户)。您只需更改绑定名称并将http://更改为net.pipe://即可。 – 2010-11-29 03:56:27

1

当网站B假冒其他用户,并您的代码指定impersonation level

我的猜测是,你没有指定足够高的模拟水平。 (授权最高,允许SiteB将权限传递给其他服务)。

我怀疑修复了网站B模拟代码将足以解决问题。

如果没有,尝试通过允许的模拟级别服务器:

<system.serviceModel> 
    <client> 
     <endpoint address="http://xxxxx/Services/xxService.svc" 
       binding="wsHttpBinding" 
       contract="IServiceContract" 
       behaviorConfiguration = "ImpersonationBehavior" /> 
    </client> 
     <behaviors> 
      <endpointBehaviors> 
       <behavior name="ImpersonationBehavior"> 
        <clientCredentials> 
         <windows allowedImpersonationLevel = "Delegation" /> <!-- The highest level --> 
        </clientCredentials> 
       </behavior> 
      <endpointBehaviors> 
     </behaviors> 
</system.serviceModel> 
0

如果您使用的是自托管的网站和我一样,为了避免这个问题(如上所述)的方式是规定在主机和客户端,wsHttpBinding安全模式= NONE。

在创建绑定,客户端和主机上,您可以使用此代码:

Dim binding as System.ServiceModel.WSHttpBinding 
binding= New System.ServiceModel.WSHttpBinding(System.ServiceModel.SecurityMode.None) 

System.ServiceModel.WSHttpBinding binding 
binding = new System.ServiceModel.WSHttpBinding(System.ServiceModel.SecurityMode.None);