首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >WCF与Silverlight 4,发布订阅UserName Auth ServiceSecurityContext.Current空引用

WCF与Silverlight 4,发布订阅UserName Auth ServiceSecurityContext.Current空引用
EN

Stack Overflow用户
提问于 2011-12-30 17:42:23
回答 1查看 478关注 0票数 1

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

问题:

每次我在使用Silverlight时尝试订阅或发布(换句话说,在任何时候,我都会传递我的用户名和密码),ServiceSecurityContext.Current.PrimaryIdentity是空的,但是它在控制台中工作得很好。而且,当访问服务时,它不会在从Silverlight访问它时击中我的自定义用户名和密码验证器,而是从控制台访问它。

我的要求是什么?

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

我愿意创建多个订阅者端点(例如,为SL使用的定制端点,为api用户创建的),但我需要与其他api用户使用相同的发布服务器(噢,是的,顺便说一句,WCF服务是作为api构建的,如果用户愿意的话,他们可以访问.我只允许他们访问订阅服务器,并阻塞发布服务器)

例如,我正在寻找解决当前问题的建议和/或故障排除帮助。这是我的一些代码

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

代码语言:javascript
运行
复制
    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

代码语言:javascript
运行
复制
   <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>

我想强调的是,我已经尝试过无数种不同的配置,但并不记得我尝试过的每一个组合。我知道我在做一些不该做的配置,但我只是想让它正常工作。另外,这里是我已经看过的链接

这一个 还有这张

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

提前感谢您的帮助

补充说明:

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

代码语言:javascript
运行
复制
<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>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-03-29 14:00:08

由于没有人回答这个问题,我将用我的调查结果来回答这个问题。我在这里寻找的是不可能的RIA服务和Silverlight的HTTPS。WCF服务此时只是不提供此功能。如果你知道这句话不是真的..请用一个解决办法回答我上面的问题。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8682265

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档