ChannelFactory 凭证 +对象是只读的
您好,当我尝试按如下方式设置工厂凭据时,问题是什么:
ChannelFactory<IWCFSeekService> factory = Factory;
if (factory != null)
{
factory.Credentials.UserName.UserName = CServiceCredentials.Instance.Username;
_Channel = factory.CreateChannel();
}
我收到一个异常,该对象是只读的。当我想设置用户名时会发生这种情况。
Greetings, what is the problem that when I try to set credentials for my factory as follows:
ChannelFactory<IWCFSeekService> factory = Factory;
if (factory != null)
{
factory.Credentials.UserName.UserName = CServiceCredentials.Instance.Username;
_Channel = factory.CreateChannel();
}
I get an exception that object is read-only. It occurs when I want to set username.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的,MSDN 文档非常清楚:
该属性仅有一个
get
访问器 - 无set访问器 -->它是只读的。另外在 MSDN 文档中:
那你来这里做什么?
更新:您无法设置客户端代理应该在通道工厂上使用的用户凭据。请参阅此 关于如何做到这一点的优秀博客文章 - 有点绕道:
第三,将这些新凭据设置为新凭据工厂中的端点行为
似乎有点奇怪和复杂,但这似乎是实现这一目标的唯一方法!
Yes, the MSDN documentation is pretty clear:
The property only has a
get
accessor - no set accessor --> it's readonly.Also in the MSDN docs:
So what is it you're doing to do here??
UPDATE: you cannot set the user credentials that your client proxy is supposed to use on the channel factory. See this excellent blog post on how to do it anyway - with a bit of a detour:
thirdly, set those new credentials as new endpoint behavior on factory
Seems a bit odd and complicated, but that seems to be the one and only way to achieve this!
为了完成这个答案,它对每个人都起作用的实际方式,如
http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/4668e261-0fd0-4ca5-91d2-497aa479f2a9/
您不需要删除,而是覆盖找到凭据:
这解决了我的问题。
To complete this answer, the actual way in which it worked for everyone as explained at
http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/4668e261-0fd0-4ca5-91d2-497aa479f2a9/
You need not to remove, but override found credentials:
This has solved my problem.
如果通过->添加服务引用则不会发生这种情况。添加服务引用->高级->添加Web引用-> Url/wsdl(本地磁盘文件)。
生成的 reference.cs 文件有所不同,并且允许您设置凭据。
该错误是因为您可能已通过第一个屏幕本身添加了引用(添加服务引用)
This will not happen if the service reference is added through -> Add service reference ->Advanced->Add Web Reference-> Url/wsdl (local disk file).
The reference.cs file generated is different and will allow you to set credentials.
The error is because you might have added the reference through first screen itself (Add service reference)