【问题标题】:WCF with Silverlight 4, Publish Subscribe UserName Auth ServiceSecurityContext.Current NULL ReferenceWCF 与 Silverlight 4,发布订阅用户名验证 ServiceSecurityContext.Current NULL 参考
【发布时间】:2012-03-29 22:00:08
【问题描述】:

我已经构建了一个 WCF 发布订阅主题服务,并且可以使用控制台应用程序成功发布/订阅(这意味着我知道它至少可以在控制台中工作),并且可以在我的 Silverlight 应用程序中成功地添加两个服务引用。

问题:

每次我在使用 Silverlight 时尝试订阅或发布(换句话说,任何时候,我都会通过我的用户名和密码),ServiceSecurityContext.Current.PrimaryIdentity 为 NULL,但它在控制台中工作正常。此外,在访问该服务时,从 Silverlight 访问它时,它不会命中我的自定义用户名和密码验证器,但它会从控制台访问。

我有什么要求?

我需要通过 Silverlight 使用我的发布订阅服务。 WCF 服务需要对用户用户名进行身份验证。 WCF 服务需要尽可能安全,同时仍允许与 Silverlight 一起使用。我必须使用 .Net,我必须使用 WCF PubSubTopic,我必须使用 Silverlight。

我愿意创建多个订阅者端点(例如,可能是一个自定义端点供 SL 使用,另一个供我的 api 用户使用),但我需要使用与我的其他 api 用户相同的发布者(哦,是的,顺便说一句,WCF 服务是作为 api 构建的,供我的用户根据需要访问...我只允许他们访问订阅者,并阻止发布者)

我正在寻找针对当前问题的示例、建议和/或故障排除帮助。这是我的一些代码

Silverlight 的 VB.NET 代码试图发布一些东西

    Private Const PUBLISHER_ENDPOINT_ADDRESS As String = "http://myserver/portal/api/v1/Publisher.svc"

    Friend Shared Sub PublishSomething()

        Dim binding As PollingDuplexHttpBinding = New PollingDuplexHttpBinding()

        Dim endpoint_address As EndpointAddress = New EndpointAddress(PUBLISHER_ENDPOINT_ADDRESS)

        Dim client As New PublisherClient(binding, endpoint_address)

        client.ClientCredentials.UserName.UserName = String.Format("{0}\{1}", Common.CompanyName, Common.UserName) 

        client.ClientCredentials.UserName.Password = "mypassword"

        Dim uUpdate As New PortalPublisherService.UserUpdatedNotification

        uUpdate.CompanyID = CompanyId

        uUpdate.CompanyName = CompanyName

        uUpdate.isAdvisor = True

        uUpdate.isMaster = True

        uUpdate.MetaNotes = "Testing from silverlight."

        uUpdate.updateById = UserId

        uUpdate.updateByName = UserName

        uUpdate.userEmail = "bill@domain.com"

        uUpdate.userId = UserId

        client.UserUpdateAsync(uUpdate)

    End Sub

这是来自服务的 web.config

   <system.serviceModel>

    <serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>

    <protocolMapping>
      <add scheme="http" binding="wsDualHttpBinding"/>
    </protocolMapping>

    <extensions>
      <bindingExtensions>
        <add name="pollingDuplexHttpBinding"
            type="System.ServiceModel.Configuration.PollingDuplexHttpBindingCollectionElement,
          System.ServiceModel.PollingDuplex, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
      </bindingExtensions>
    </extensions>

    <behaviors>

      <serviceBehaviors>
        <!--primary behavior-->
        <behavior name="Portal.Api.Behavior">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="false"/>
          <serviceCredentials>
            <serviceCertificate findValue="PortalApiCert" storeLocation="LocalMachine" storeName="TrustedPeople" x509FindType="FindBySubjectName"/>
            <clientCertificate>
              <authentication certificateValidationMode="PeerOrChainTrust" revocationMode="NoCheck"/>
            </clientCertificate>
            <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="Portal.Web.UserPassAuth, Portal.Web"/>
          </serviceCredentials>
        </behavior>
      </serviceBehaviors>

    </behaviors>

    <bindings>

<pollingDuplexHttpBinding>
        <binding name="pollingBindingConfig"
                 closeTimeout="00:01:00"
                 openTimeout="00:01:00"
                 receiveTimeout="00:10:00"
                 sendTimeout="00:01:00"
                 transferMode="Buffered"
                 hostNameComparisonMode="StrongWildcard"
                 maxBufferPoolSize="5242880"
                 maxBufferSize="655360"
                 maxReceivedMessageSize="655360">
          <readerQuotas maxDepth="32"
                        maxStringContentLength="81920"
                        maxArrayLength="163840"
                        maxBytesPerRead="16384"
                        maxNameTableCharCount="163840" />
          <security mode="TransportCredentialOnly" />
        </binding>
      </pollingDuplexHttpBinding>

    </bindings>
    <services>
    <!--publisher endpoint configuration settings-->
      <service behaviorConfiguration="Portal.Api.Behavior" name="Portal.Web.Publisher">
        <endpoint address="" binding="pollingDuplexHttpBinding" contract="Portal.Publisher.IPublisher" bindingConfiguration="pollingBindingConfig"/>
        <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="meta"/>
        <host>
          <baseAddresses>
            <add baseAddress="http://server/portal/api/v1/IPublisher"/>
          </baseAddresses>
        </host>
      </service>
    </services>
  </system.serviceModel>

我想强调一下,我已经尝试过一百万种不同的配置,但我无法记住我尝试过的每一种组合。我知道我在配置中做了一些我不应该做的事情,但我只是想让它开始工作。另外,这里是我已经看过的链接

this one and this one

还有更多,但是......好吧......这是漫长的一天......

提前感谢您的帮助

补充说明:

这是我在非 Silverlight 实现中成功使用的绑定

<wsDualHttpBinding>
    <binding name="Portal.Api.Binding" maxReceivedMessageSize="2147483647" sendTimeout="00:10:00">
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
      <security mode="Message">
        <message clientCredentialType="UserName" negotiateServiceCredential="false"/>
      </security>
    </binding>
  </wsDualHttpBinding>

【问题讨论】:

    标签: silverlight wcf publish-subscribe


    【解决方案1】:

    由于没有人回答这个问题,我将用我的发现来回答这个问题。使用 RIA 服务和通过 HTTPS 的 Silverlight 无法实现我在这里寻找的内容。 WCF RIA 服务目前不提供此功能。如果您知道这句话不是真的.. 请用解决方案回答我上面的问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多