【问题标题】:WCF windows authenticationWCF 窗口身份验证
【发布时间】:2011-03-09 06:39:04
【问题描述】:

我希望我们的 WCF 服务返回当前登录用户的名称。我在我的服务中调用它,

HttpContext.Current.User.Identity.Name

但是,我不希望在我的 silverlight 应用程序调用 WCF 服务时向用户显示 NT 质询。目前我禁用了匿名访问并启用了集成身份验证,但由于这个原因,我无法将服务添加到我在 VS2010 中的服务引用中。我该怎么做?此外,WCF 服务的 web.config 设置应该是什么。我目前正在使用安全模式设置为无的 basicHttpBinding。

添加 Web.config: 服务器:

<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<behaviors>
<serviceBehaviors>
<behavior name="MyService.MyServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_MyService" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" receiveTimeout="00:40:00" openTimeout="00:40:00" closeTimeout="00:40:00" sendTimeout="00:40:00">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
<security mode="None"/>
</binding>
</basicHttpBinding>
<customBinding>
<binding name="MyService.MyService.customBinding0">
<binaryMessageEncoding/>
<httpTransport/>
</binding>
</customBinding>
</bindings>
<services>
<service behaviorConfiguration="MyService.MyServiceBehavior" name="MyService.MyService">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_MyService" name="BasicHttpBinding_MyService" contract="MyService.IMyService"/>
</service>
</services>
</system.serviceModel>

客户:

<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/> 
<behaviors>
<serviceBehaviors>
<behavior name="MyService_Behavior">
<serviceDebug includeExceptionDetailInFaults="true"/>
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="r1">
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_MyService" closeTimeout="00:03:00" openTimeout="00:03:00" receiveTimeout="00:10:00" sendTimeout="00:03:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
<security mode="None"/>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8080/MyService/MyService.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_MyService" contract="MyService.IMyService" name="BasicHttpBinding_MyService" behaviorConfiguration="r1"/>
</client>
</system.serviceModel>

【问题讨论】:

  • 您在 IIS 中有哪些设置?
  • 我已禁用匿名访问并启用集成 Windows 身份验证
  • 能否将服务器和客户端的 web.config 添加到问题中?
  • 请参阅stackoverflow.com/questions/9588265/… 了解有关 Windows 身份验证的一些观点

标签: c# silverlight wcf


【解决方案1】:

您需要在服务绑定配置中启用 Windows 身份验证。 IE。 在绑定定义部分引用此绑定 cinfig

<bindings>
      <basicHttpBinding>
          <binding name="basicBindingCfg">
              <security mode="TransportCredentialOnly">
                  <transport clientCredentialType="Windows" />
              </security>
          </binding>
      </basicHttpBinding>
  </bindings>

同样在你的 web 配置中你需要设置 windows 身份验证

并允许用户使用授权标签:

   <authentication mode="Windows"/>
   <authorization>
        <allow roles="<NT group>"/>
        <allow users="<user name>"/>
        <deny users="*"/>
    </authorization>

【讨论】:

    【解决方案2】:

    尝试使用下面的 psudo 客户端配置将以下端点行为添加到您的端点

    <behaviors>
        <endpointBehaviors>
            <behavior name="WindowsBehavior">
                <clientCredentials>
                    <windows allowNtlm="false" allowedImpersonationLevel="Delegation"></windows>
                </clientCredentials>
                <dataContractSerializer maxItemsInObjectGraph="4194304"></dataContractSerializer>
            </behavior>
        </endpointBehaviors>
    </behaviors>
    
    
    <endpoint address="http://server/web.svc" behaviorConfiguration="WindowsBehavior" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_Service" contract="IMyContract" name="BasicHttpBinding_Service">
    

    【讨论】:

      猜你喜欢
      • 2013-04-14
      • 2011-08-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-07
      • 2015-04-14
      相关资源
      最近更新 更多