如何使用自定义 IChannel 或 IChannelFactory 访问 ClientCredentials?
我正在 WCF 中创建自定义通道以实现自定义安全协议。不,别逃!没那么可怕!
验证服务上的协议相对简单。困难的部分是根据客户端凭据将安全信息添加到请求中。
我想要做的是从我的通道实现中访问 ClientCredentials
对象(附加到正在使用的 ClientProxy
的对象)。通常,我可以通过 访问此内容我尝试访问的端点的 ServiceEndpoint
实例上的 Behaviors
属性:
var credentials = channel.Endpoint.Behaviors.Find<ClientCredentials>();
但是,我似乎找不到访问服务端点的方法该频道关联于从通道本身内部 - 从 ChannelBase
类中可用的元数据几乎为零。
有没有办法获取与我的频道关联的端点?是否有其他方法可以在客户端访问客户端凭据?
I'm creating a custom channel in WCF in order to implement a custom security protocol. No, don't run away! It's not that scary!
Verifying the protocol on the service is relatively simple. The hard part is adding the security information to the request based on the client credentials.
What I want to do is access the ClientCredentials
object (the one attached to the ClientProxy
in use) from within my channel implementation. Normally, I'd get access to this through the Behaviors
property on the ServiceEndpoint
instance for the endpoint I'm trying to reach:
var credentials = channel.Endpoint.Behaviors.Find<ClientCredentials>();
However, I can't seem to find a way to access the service endpoint the channel is associated with from within the channel itself - almost zero metadata is available from the ChannelBase
class.
Is there a way to get the endpoint my channel is associated with? Is there any alternative way to access the client credentials on the client-side?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
标准安全通道不在内部使用
ClientCredentials
。相反,它们与由ClientCredentials
构造的SecurityTokenManager
进行通信。我建议使用一些反汇编程序来浏览整个实现。一般来说,您的
BindingElement
应该构建ChannelLister
和ChannelFactory
并向它们传递所需的所有信息。Standard security channels don't use
ClientCredentials
internally. They instead talk withSecurityTokenManager
which is constructed fromClientCredentials
. I recommend using some disassembler to browse whole implementation.Generally your
BindingElement
should build bothChannelLister
andChannelFactory
and pass them all information they need.实施您自己的客户服务。
例如;
现在称呼它...
Implement you own client service.
For example;
Now call it...