为新通道设置用户名凭证,无需创建新工厂
我有后端服务和前端服务。他们通过可信子系统模式进行通信。我想将用户名从前端传输到后端,并通过用户名凭据执行此操作,如下所示:
http://msdn.microsoft.com/en-us/library/ms730288.aspx
这在我们的场景中不起作用,前端通过以下方式构建后端服务通道工厂:
channelFactory = new ChannelFactory<IBackEndService>(.....);
创建一个新的通道是通过模具通道工厂完成的。我只能设置一次凭据,然后出现用户名对象是只读的异常。
channelFactory.Credentials.Username.Username = "myCoolFrontendUser";
var channel = channelFactory.CreateChannel();
有没有一种方法可以只创建一次通道工厂,因为创建通道工厂的成本很高,然后在创建通道时指定用户名凭据?
I have a backend service and front-end services. They communicate via the trusted subsystem pattern. I want to transfer a username from the frontend to the backend and do this via username credentials as found here:
http://msdn.microsoft.com/en-us/library/ms730288.aspx
This does not work in our scenerio where the front-end builds a backend service channel factory via:
channelFactory = new ChannelFactory<IBackEndService>(.....);
Creating a new channel is done via die channel factory. I can only set the credentials one time after that I get an exception that the username object is read-only.
channelFactory.Credentials.Username.Username = "myCoolFrontendUser";
var channel = channelFactory.CreateChannel();
Is there a way to create the channel factory only one time as this is expensive to create and then specify username credential when creating a channel?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现这是不可能的。我知道向每个标识用户的调用添加一个自定义标头值。您需要这样做,因为您不想为每个可能访问前端的用户创建一个工厂。除此之外,建立工厂的成本很高。
I found out that this is not possible. I know add a custom header value to each call that identifies the user. You need to do this as you do not want to create a factory for each user that could hit your front-end. Besides that, creating factories is expensive.