如果配置位于字符串中,是否使用 new ChannelFactory(string)?
我想使用 ChannelFactory为给定端点创建 WCF 客户端。
问题是我没有 web.config 或 app.config,但我确实在字符串中拥有整个
XML 块。
当我已经有了配置时,我不想手动解析它并以编程方式创建 BIndings 和端点。
有没有办法告诉 ChannelFactory 仅使用该块作为其配置?或者至少创建一个 服务端点?
I would like to use the ChannelFactory to create a WCF Client for a given endpoint.
The problem is that I don't have a web.config or app.config, but I do have the whole <system.serviceModel>
XML block in a string.
I do not want to manually parse that out and programatically create the BIndings and Endpoints when I already have the configuration.
Is there a way to tell the ChannelFactory to just use that block as it's configuration? Or at least create a ServiceEndpoint?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
此博客条目。
它不像一行代码那么简单,但至少它的工作级别高于原始 XML。
There's a technique described in this blog entry.
It isn't as simple as one line of code, but at least it's working at a level higher than raw XML.
您可以手动创建绑定和端点地址来创建 CHannelFactory 的实例,例如:
然后您可以尝试使用factory.CreateChannel() 在您的 ServiceEnpoint、Behaviors 等之前探索它的成员。
希望这会有所帮助,谢谢。
You can manually create binding and endpoint address to create an instance of the CHannelFactory, something like:
Then you can try using factory.CreateChannel() to explore the members of it before your ServiceEnpoint, Behaviors, etc.
Hope this help, thanks.
找到了更好的解决方案:
ConfigurationChannelFactory
允许从自定义配置创建 WCF 通道。Found a better solution:
ConfigurationChannelFactory<TChannel>
allows creating a WCF Channel from a custom configuration.