如果配置位于字符串中,是否使用 new ChannelFactory(string)?

发布于 2024-11-02 09:00:00 字数 496 浏览 2 评论 0原文

我想使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

橘味果▽酱 2024-11-09 09:00:00

此博客条目

它不像一行代码那么简单,但至少它的工作级别高于原始 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.

梦醒灬来后我 2024-11-09 09:00:00

您可以手动创建绑定和端点地址来创建 CHannelFactory 的实例,例如:

   BasicHttpBinding binding = new BasicHttpBinding() { 
       Name = "Bindingname"
       // Goes all the necessary members to set.
   };

   EndpointAddress endpoint = new EndpointAddress("http://serviceendpoint.com");
   ChannelFactory<IContract> factory = new ChannelFactory<IContract>(binding, endpoint);

然后您可以尝试使用factory.CreateChannel() 在您的 ServiceEnpoint、Behaviors 等之前探索它的成员。

希望这会有所帮助,谢谢。

You can manually create binding and endpoint address to create an instance of the CHannelFactory, something like:

   BasicHttpBinding binding = new BasicHttpBinding() { 
       Name = "Bindingname"
       // Goes all the necessary members to set.
   };

   EndpointAddress endpoint = new EndpointAddress("http://serviceendpoint.com");
   ChannelFactory<IContract> factory = new ChannelFactory<IContract>(binding, endpoint);

Then you can try using factory.CreateChannel() to explore the members of it before your ServiceEnpoint, Behaviors, etc.

Hope this help, thanks.

月光色 2024-11-09 09:00:00

找到了更好的解决方案:ConfigurationChannelFactory允许从自定义配置创建 WCF 通道。

Found a better solution: ConfigurationChannelFactory<TChannel> allows creating a WCF Channel from a custom configuration.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文