0

我正在尝试使用 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/'.
4

1 回答 1

2

假设您使用的是 WCF 4.0,那么我认为您会看到称为默认端点的 WCF 4 功能的人工制品。

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

于 2011-07-13T21:34:00.597 回答