Silverlight 3 + WCF和IIS基本身份验证

时间:2009-09-29 23:07:59

标签: wcf iis silverlight-3.0

我有以下问题。在我的机器上我有一个SL 3应用程序,它基本上包括:

* Client app (SL)
* Web app (.Net 3.5)
* Communication with the database handled by WCF

该网站托管在我的IIS上,并设置了以下身份验证:

* Anonymous access: off
* Basic authentication: on
* Integrated Windows authentication: on

我的绑定设置如下:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_IWcfPortal" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
                    <security mode="TransportCredentialOnly" />
                </binding>
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost/MyApp/WCFPortal.svc" binding="basicHttpBinding"
                bindingConfiguration="BasicHttpBinding_IWcfPortal" contract="WcfPortal.IWcfPortal"
                name="BasicHttpBinding_IWcfPortal" />
        </client>
    </system.serviceModel>
</configuration>

的Web.config:

  <authentication mode="Windows" />
  <identity impersonate="true" />

当我导航到我的网站时,系统会提示我输入用户名和密码。正确填写后,我可以访问该站点,但数据库通信不起作用。当我转到localhost / MyApp / WcfPortal.svc时,我收到以下错误:

此服务的安全设置需要“匿名”身份验证,但不会为承载此服务的IIS应用程序启用此功能。

我尝试将<transport clientCredentialType="Windows" />添加到basicHttpBinding中的安全性,但VS向我发出警告“未声明'clientCredentialType'属性。”。

如果有人能帮助我,我将非常感激。

2 个答案:

答案 0 :(得分:1)

我解决了我的问题。原来我必须在两个地方更改basicHttpBinding:ServiceReferences.ClientConfig和Web.Config

ServiceReferences.ClientConfig:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IWcfPortal" maxBufferSize="2147483647"
            maxReceivedMessageSize="2147483647">
          <security mode="TransportCredentialOnly" />
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost/MyApp/WCFPortal.svc" binding="basicHttpBinding"
          bindingConfiguration="BasicHttpBinding_IWcfPortal" contract="WcfPortal.IWcfPortal"
          name="BasicHttpBinding_IWcfPortal" />
    </client>
  </system.serviceModel>
</configuration>

的Web.config:

...

    <authentication mode="Windows" />
...

    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IWcfPortal" maxBufferSize="10000000" maxReceivedMessageSize="10000000" receiveTimeout="00:10:00" sendTimeout="00:10:00" openTimeout="00:10:00" closeTimeout="00:10:00">
            <security mode="TransportCredentialOnly">
                <transport clientCredentialType="Ntlm" />
            </security>
            <readerQuotas maxBytesPerRead="10000000" maxArrayLength="10000000" maxStringContentLength="10000000"/>
        </binding>
      </basicHttpBinding>
    </bindings> 

答案 1 :(得分:0)

不幸的是,要在IIS6下托管此服务,您必须启用匿名身份验证。