使用WCF服务调用发送Windows凭据

时间:2015-05-14 17:47:01

标签: asp.net .net wcf windows-authentication

我从我的ASP.NET应用程序(.Net 4.5和IIS 7)调用WCF服务。 Web应用程序配置为使用Windows身份验证。

<authentication mode="Windows" />

我正在尝试将Windows用户凭据作为身份原则发送到我的服务。在我的服务端,我将手动执行一些额外的授权逻辑。但是我没有在服务端获得WindowsPrinciple。相反,我总是得到GenericPrinciple类型,因此原则名称是空白的。我是WCF配置的新手。我到底错过了什么?

Web应用程序和WCF当前都在同一台计算机上的IIS 7中托管。

这是客户端的web.config设置。

<system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding name="BasicHttpBidning_IService" maxReceivedMessageSize="2147483647">
    </binding>
  </basicHttpBinding>

<client>
  <endpoint address="http://localhost/MyWebServiceApp/API/MyAPIService.svc"
      binding="basicHttpBinding" bindingConfiguration="BasicHttpBidning_IService"
      contract="Application.API.IService"
      name="BasicHttpBidning_IService" >
  </endpoint>
</client>
</system.serviceModel> 

服务方:

<service name="MyAPIService" behaviorConfiguration="PublicServiceTypeBehaviors">
    <endpoint address="" binding="basicHttpBinding" bindingConfiguration="BasicHttpBidning_IPublicService" contract="Application.API.IService" name="BasicHttpBidning_IService" />
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>

<system.serviceModel>
<client />
<serviceHostingEnvironment multipleSiteBindingsEnabled="false" minFreeMemoryPercentageToActivateService="1" />
<bindings>
  <basicHttpBinding>
    <binding name="BasicHttpBidning_IPublicService" maxReceivedMessageSize="2147483647" />
    </basicHttpBinding>
</bindings>
<behaviors>
  <endpointBehaviors>
    <behavior name="WebHttpBidning_IPublicService">
      <webHttp/>
    </behavior>
  </endpointBehaviors>  
  <serviceBehaviors>
    <behavior name="PublicServiceTypeBehaviors">
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
    <behavior>
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
</system.serviceModel>

1 个答案:

答案 0 :(得分:0)

您已定义名为“PublicServiceTypeBehaviors”的ServiceBehavior,现在您只需要使该行为包含WCF的一些内置身份验证和授权功能。

WindowsAuthentication是您在ServiceCrendentials下所需要的。

如果需要,可以添加ServiceAuthorization和相关角色提供程序。

相关问题