【问题标题】:WCF(HTTPS,UserName) calling by SilverLightSilverLight 调用 WCF(HTTPS,UserName)
【发布时间】:2023-03-22 03:15:01
【问题描述】:

我已经通过 HTTPS 创建了具有传输安全性的 wcf 服务。此外,我使用http://msdn.microsoft.com/en-us/library/cc949025.aspx 中所述的用户名身份验证,因此我可以使用我的 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 保持沉默。

非常感谢

【问题讨论】:

  • 能否请您发布您的 web.config 的绑定节点。那么我们可以看看basicHttpBinding是怎么配置的呢? - 谢谢

标签: silverlight wcf


【解决方案1】:

你在使用 basicHttpBinding 吗? sl app 和 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>

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/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 应用程序。看看这些吧:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-30
    • 2010-09-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多