2010-03-24 66 views
1

我已經通過HTTPS創建了具有傳輸安全性的wcf服務。我還使用用戶名身份驗證,如http://msdn.microsoft.com/en-us/library/cc949025.aspx所述,所以我可以使用我的Membership,RoleProvider。當我使用ASP.NET的這項服務工作時,一切正常通過SilverLight調用WCF(HTTPS,UserName)

var client = new RegistratorClient(); 
    client.ClientCredentials.UserName.UserName = ConfigurationManager.AppSettings["registratorLogin"]; 
    client.ClientCredentials.UserName.Password = ConfigurationManager.AppSettings["registratorPassword"]; 

但是在我的SilverLight應用程序中,我無法做到這一點。當我嘗試設置證書並打電話給wcf時,我得到了帶有用戶名和密碼的標準瀏覽器窗口。當我插入SL應用程序時效果不錯,但是這個消息非常惱人。我的SL配置中無法使用clientCredentialType =「Basic」。

我應該怎麼做才能調用我的WCF。

非常感謝

+0

能否請您發表您的web.config您的綁定節點。所以我們可以看到basicHttpBinding是如何配置的? - 謝謝 – DaveB 2010-03-26 16:38:42

回答

0

您使用的是basicHttpBinding嗎?並且是sl應用程序和svc在同一個域上?

我有(我認爲)一個類似的設置 - silverlight 3.0/wcf託管通過https使用窗體身份驗證。

我會複製我所有的相關配置,以防你失去了一些東西。

ServiceReferences.ClientConfig(不得不刪除了 '配置' 標籤,否則整個塊消失):

<system.serviceModel> 
    <bindings> 
     <basicHttpBinding> 
      <binding name="BasicHttpBinding_PassportService" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" 
       textEncoding="utf-8"> 
       <security mode="Transport"> 
       </security> 
      </binding> 
     </basicHttpBinding> 
    </bindings> 
    <client> 
     <endpoint address="https://domain/service.svc" 
      binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_PassportService" 
      contract="PassportService.PassportService" name="BasicHttpBinding_PassportService" /> 
    </client> 
</system.serviceModel> 

serviceModel在web.config中:

<system.serviceModel> 
    <behaviors> 
     <serviceBehaviors> 
      <behavior name="ProjectPassport.Web.PassportServiceBehavior"> 
       <serviceMetadata httpGetEnabled="true" httpGetUrl="http://domain/service.svc" /> 
       <serviceDebug includeExceptionDetailInFaults="true" /> 
       <dataContractSerializer maxItemsInObjectGraph="2147483647" /> 
      </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <bindings> 
     <basicHttpBinding> 
      <binding name="basicHttpsBinding"> 
       <security mode="Transport"> 
        <transport clientCredentialType="None"/> 
       </security> 
      </binding> 
     </basicHttpBinding> 
    </bindings> 
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" /> 
    <services> 
     <service behaviorConfiguration="ProjectPassport.Web.PassportServiceBehavior" 
     name="ProjectPassport.Web.PassportService"> 
      <endpoint address="" binding="basicHttpBinding" bindingConfiguration="basicHttpsBinding" 
       contract="ProjectPassport.Web.PassportService" /> 
     </service> 
    </services> 
</system.serviceModel> 

和我的認證/授權/會員配置:

<authentication mode="Forms"> 
     <forms loginUrl="Home.aspx" protection="All" timeout="80" name="AppName" path="/" requireSSL="false" slidingExpiration="true" defaultUrl="Manage.aspx" cookieless="UseCookies" enableCrossAppRedirects="false"/> 
    </authentication> 

    <authorization> 
     <deny users="?"/> 
     <!----> 
     <allow users="*"/> 
    </authorization> 
    <membership defaultProvider="SqlProvider" userIsOnlineTimeWindow="15"> 
     <providers> 
      <clear/> 
      <add name="SqlProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="LocalSqlServer" applicationName="MyApplication" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" passwordFormat="Clear" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="4" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="50" passwordStrengthRegularExpression=""/> 
     </providers> 
    </membership> 

另外,別忘了js/clientBi應授權n/wcf服務地點。加入位置標籤:

<location path="ClientBin"> 
    <system.web> 
     <authorization> 
      <allow users="*"/> 
     </authorization> 
    </system.web> 
</location> 
<location path="service.svc"> 
    <system.web> 
     <authorization> 
      <allow users="*"/> 
     </authorization> 
    </system.web> 
</location> 

等等

編輯:鏈接你指的是針對的WinForms。如果我沒有弄錯,你正在構建silverlight 3應用程序。看看這些來代替:

http://msdn.microsoft.com/en-us/library/dd560704%28VS.95%29.aspx

http://www.eggheadcafe.com/tutorials/aspnet/7cc2760f-50f2-492d-9d62-48ad5c7f70b4/aspnet-membership-and-ro.aspx