WCF Web服务中的激活错误使用basicHttpBinding,Windpws-Authentication&模拟

时间:2011-07-13 19:51:57

标签: wcf wcf-security windows-authentication impersonation basichttpbinding

我正在尝试使用Windows身份验证在IIS中托管WCF Web服务。由于限制,我们必须使用basicHttpBinding&使用模拟(模仿调用者的身份以访问链中的资源)。

我声明性地启用了对我的WCF服务的操作合同的模拟:

 [OperationBehavior(Impersonation = ImpersonationOption.Required)]

我的web.config是:

    <system.serviceModel>
      <behaviors>
        <serviceBehaviors>
          <behavior>
            <serviceMetadata httpGetEnabled="true"/>
            <serviceDebug includeExceptionDetailInFaults="true"/>
          </behavior>
        </serviceBehaviors>
      </behaviors>
      <bindings>
        <basicHttpBinding>        
          <binding name="basic">          
            <security mode="TransportCredentialOnly">
              <transport clientCredentialType="Windows">              
              </transport>            
            </security>          
          </binding>
        </basicHttpBinding>
      </bindings>
      <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
      <services>
        <service name="NotesService">
          <endpoint address="http://Client1.osp.local:15000/NotesService/NotesService.svc" bindingConfiguration="basic" binding="basicHttpBinding"  contract="NotesService.ServiceContract.INotesService">
            <identity>
              <servicePrincipalName value="HTTP/Client1.osp.local:15000"/>            
            </identity>          
          </endpoint>        
        </service>
      </services>
    </system.serviceModel>

但是,我收到了激活错误。我错过了什么?

我得到的错误是:

The contract operation 'Process' requires Windows identity for automatic 
impersonation. A Windows identity that represents the caller is not provided by 
binding ('BasicHttpBinding','http://tempuri.org/') for contract 
('NotesService','http://tempuri.org/'.

1 个答案:

答案 0 :(得分:2)

假设您正在使用WCF 4.0,那么我认为您正在看到一个名为默认端点的WCF 4功能的伪像。

在服务名称中,您需要提供服务的完全限定名称(包括命名空间)。假设NotesService在命名空间中,那么当您创建ServiceHost时,它不会在配置文件中找到匹配项。如果您在ServiceHost构造函数中提供HTTP基地址,那么它将使用其默认配置(无身份验证)连接basicHttpBinding,这将产生您看到的错误

相关问题