修改启用Silverlight的WCF服务以使用Windows身份验证进行协作

时间:2009-10-28 12:52:21

标签: silverlight authentication silverlight-3.0 windows-authentication

我有一个Silverlight应用程序,并添加了启用Silverlight的WCF服务。我想将此部署为使用Windows身份验证的Intranet解决方案,而无需匿名访问。

开箱即用,WCF服务将以下设置添加到web.config:

<system.serviceModel>
  <behaviors>
   <serviceBehaviors>
    <behavior name="WindowsAuthTest.Web.Service1Behavior">
     <serviceMetadata httpGetEnabled="true" />
     <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
   </serviceBehaviors>
  </behaviors>
  <bindings>
   <customBinding>
    <binding name="customBinding0">
     <binaryMessageEncoding />
     <httpTransport />
    </binding>
   </customBinding>
  </bindings>
  <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
  <services>
   <service behaviorConfiguration="WindowsAuthTest.Web.Service1Behavior"
    name="WindowsAuthTest.Web.Service1">
    <endpoint address="" binding="customBinding" bindingConfiguration="customBinding0"
     contract="WindowsAuthTest.Web.Service1" />
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
   </service>
  </services>
 </system.serviceModel>

将此服务引用添加到silverlight项目时,这些设置将添加到ServiceReferences.ClientConfig:

<system.serviceModel>
        <bindings>
            <customBinding>
                <binding name="CustomBinding_Service1">
                    <binaryMessageEncoding />
                    <httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
                </binding>
            </customBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:3568/Service1.svc" binding="customBinding"
                bindingConfiguration="CustomBinding_Service1" contract="ServiceReference1.Service1"
                name="CustomBinding_Service1" />
        </client>
    </system.serviceModel>

如何修改这些设置以使其能够与Windows身份验证配合使用?有可能吗?

1 个答案:

答案 0 :(得分:0)

尝试添加:

security mode =“TransportCredentialOnly

e.g。

<binding name="BasicHttpBinding_IUserWebService" maxBufferSize="2147483647"
           maxReceivedMessageSize="2147483647">
       <security mode="TransportCredentialOnly" />
</binding>

在web.config中我们使用basicHttpBinding,例如

 <bindings>
      <basicHttpBinding>
        <binding name="customBasicHttpBinding" maxBufferSize="2147483647"
          maxReceivedMessageSize="2147483647">
          <security mode="TransportCredentialOnly">
            <transport clientCredentialType="Windows" proxyCredentialType="None" />
          </security>
        </binding>
      </basicHttpBinding>      
 </bindings>