尽管手动创建通道并使用STS自行发出令牌并没有错,但您可以利用WIF框架为您执行此操作。
如果您通过配置来配置您的客户端以了解STS,则框架将使用您在通道上设置的消息凭证自行检索令牌。然后框架将在通道的凭证上设置“IssuedToken”属性。
<ws2007HttpBinding>
<binding name="ws">
<security mode="TransportWithMessageCredential">
<message establishSecurityContext="false"
negotiateServiceCredential="true"
clientCredentialType="UserName" />
</security>
</binding>
</ws2007HttpBinding>
<customBinding>
<binding name="FederationDuplexTcpMessageSecurityBinding">
<reliableSession />
<security authenticationMode="SecureConversation">
<secureConversationBootstrap authenticationMode="IssuedTokenForSslNegotiated">
<issuedTokenParameters>
<issuer address="https://IdentityServer.domain/issue/wstrust/mixed/username" binding="ws2007HttpBinding" bindingConfiguration="ws" />
<issuerMetadata address="https://IdentityServer.domain/issue/wstrust/mex" />
<additionalRequestParameters>
<wsp:AppliesTo xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
<EndpointReference xmlns="http://www.w3.org/2005/08/addressing">
<Address>RelyingParty.com</Address>
</EndpointReference>
</wsp:AppliesTo>
</additionalRequestParameters>
</issuedTokenParameters>
</secureConversationBootstrap>
</security>
<tcpTransport />
</binding>
</customBinding>
上面的代码片段展示了如何使用安全对话和secureConversationBootstrap照顾联合安全性的创建双工通道。
这样做的一个优点是您也可以设置您自己的依赖方URI,因此您不必使用WCF端点作为您的依赖方标识符。
,您还需要建立联合服务行为,使WIF如下(useIdentityConfiguration是很重要的,因为它原来WIF上):
<behavior name="FederatedServiceBehaviour">
<clientCredentials useIdentityConfiguration="true" supportInteractive="false" >
<serviceCertificate/>
</clientCredentials>
</behavior>
设置服务端点记录在这里:http://msdn.microsoft.com/en-us/library/cc668765(v=vs.110).aspx(在一定程度上)
据我可以看到DuplexChannelFactory本身公开没有方法创建频道与发出的令牌,而通过实例上下文。
希望这会有所帮助!