我通过HTTPS创建了带传输安全性的wcf服务。我也使用http://msdn.microsoft.com/en-us/library/cc949025.aspx中描述的UserName身份验证,因此我可以使用我的Membership,RoleProvider。当我使用ASP.NET处理此服务时,一切正常
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 :(得分:0)
您使用的是basicHttpBinding吗?并且是同一个域上的sl app和svc?
我有(我认为)类似的设置 - 使用表单身份验证在https上托管的silverlight 3.0 / wcf。
我将复制所有相关的配置文件,以防你遗漏某些内容。
ServiceReferences.ClientConfig(必须删除'configuration'标记,否则整个块消失):
<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>
web.config中的serviceModel:
<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 / clientBin / 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 app。看看这些:
http://msdn.microsoft.com/en-us/library/dd560704%28VS.95%29.aspx