2010-10-26 140 views
1

我有一個wcf雙工服務,可以在silverlight中正常工作。但我想在Windows控制檯應用程序中使用相同的服務。我的如下代碼:在控制檯應用程序中使用wcf雙工服務

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中的BindingElements堆疊不正確或順序錯誤。堆棧底部需要傳輸。 BindingElements的推薦順序是:TransactionFlow,ReliableSession,Security,CompositeDuplex,OneWay,StreamSecurity,MessageEncoding,[...]

你能幫助我嗎?提前致謝。

回答

1

問題是PollingDuplexHttpBinding和相關綁定元素僅在Silverlight API中可用。所以,當你開始一個新的.NET項目(在你的案例中的控制檯應用程序),你不能使用相同的代碼,因爲.NET不包含PollingDuplexBindingElement

相關問題