我已经构建了一个WCF发布订阅主题服务,并且可以使用控制台应用程序成功地发布/订阅(这意味着我知道它至少在控制台中工作),并且可以在Silverlight应用程序中成功地向这两个服务引用添加两个服务引用。
问题:
每次我在使用Silverlight时尝试订阅或发布(换句话说,在任何时候,我都会传递我的用户名和密码),ServiceSecurityContext.Current.PrimaryIdentity是空的,但是它在控制台中工作得很好。而且,当访问服务时,它不会在从Silverlight访问它时击中我的自定义用户名和密码验证器,而是从控制台访问它。
我的要求是什么?
我需要通过Silverlight使用我的发布订阅服务。WCF需要用户UserName身份验证。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>
我想强调的是,我已经尝试过无数种不同的配置,但并不记得我尝试过的每一个组合。我知道我在做一些不该做的配置,但我只是想让它正常工作。另外,这里是我已经看过的链接
这一个 还有这张
还有更多但是..。好吧..。这是漫长的一天。
提前感谢您的帮助
补充说明:
这是我在非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>
发布于 2012-03-29 14:00:08
由于没有人回答这个问题,我将用我的调查结果来回答这个问题。我在这里寻找的是不可能的RIA服务和Silverlight的HTTPS。WCF服务此时只是不提供此功能。如果你知道这句话不是真的..请用一个解决办法回答我上面的问题。
https://stackoverflow.com/questions/8682265
复制相似问题