在控制台应用程序中使用 wcf 双工服务

发布于 2024-09-29 06:28:08 字数 947 浏览 2 评论 0原文

我有一个 wcf 双工服务,在 silverlight 中工作正常。但我想在 Windows 控制台应用程序中使用相同的服务。我的代码如下:

   var context = new InstanceContext(this);
   var address = new EndpointAddress("http://localhost:31881/PubSubService.svc");
   var binding = new CustomBinding(
                 new PollingDuplexBindingElement(),
                 new BinaryMessageEncodingBindingElement(),
                 new HttpTransportBindingElement());

    var client = new PubSubClient(context, binding, address);
    client.Publish("topic", "content");

App.config 为“空”:

   <?xml version="1.0" encoding="utf-8" ?>
     <configuration>
   </configuration>

它给了我一个错误:

绑定“CustomBinding”不支持创建任何通道类型。这通常表明 CustomBinding 中的 BindingElement 堆叠不正确或顺序错误。堆栈底部需要一个传输。 BindingElements 的推荐顺序是:TransactionFlow、ReliableSession、Security、CompositeDuplex、OneWay、StreamSecurity、MessageEncoding、[...]

你能帮我吗?提前致谢。

I have a wcf duplex service with work fine in silverlight. but the same service I want to consume in windows console application. My code as follow:

   var context = new InstanceContext(this);
   var address = new EndpointAddress("http://localhost:31881/PubSubService.svc");
   var binding = new CustomBinding(
                 new PollingDuplexBindingElement(),
                 new BinaryMessageEncodingBindingElement(),
                 new HttpTransportBindingElement());

    var client = new PubSubClient(context, binding, address);
    client.Publish("topic", "content");

App.config is "empty":

   <?xml version="1.0" encoding="utf-8" ?>
     <configuration>
   </configuration>

It give me an error:

Binding 'CustomBinding' doesn't support creating any channel types. This often indicates that the BindingElements in a CustomBinding have been stacked incorrectly or in the wrong order. A Transport is required at the bottom of the stack. The recommended order for BindingElements is: TransactionFlow, ReliableSession, Security, CompositeDuplex, OneWay, StreamSecurity, MessageEncoding, [...]

Could you help me? Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

待"谢繁草 2024-10-06 06:28:08

问题是 PollingDuplexHttpBinding 和相关绑定元素仅在 Silverlight API 中可用。因此,当您启动新的 .NET 项目(在您的情况下为控制台应用程序)时,您不能使用相同的代码,因为 .NET 不包含 PollingDuplexBindingElement

The problem is that PollingDuplexHttpBinding and related binding element is available only in Silverlight API. So when you start new .NET project (Console application in your case) you can't use the same code, because .NET does not contain PollingDuplexBindingElement

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