2012-02-27 49 views
1

我正在編寫一個雙工服務,供Silverlight 5客戶端使用。我的服務器配置看起來像這樣(在適當的地方很明顯) -PollingDuplexHttpBinding和DuplexChannelFactory - 'ContractFilter不匹配在EndpointDispatcher'

  <bindingExtensions> 
       <add name="pollingDuplexHttpBinding" 
        type="System.ServiceModel.Configuration.PollingDuplexHttpBindingCollectionElement, System.ServiceModel.PollingDuplex, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/> 
      </bindingExtensions> 

<pollingDuplexHttpBinding> 
       <binding name="multipleMessagesPerPollPollingDuplexHttpBinding" 
         duplexMode="MultipleMessagesPerPoll" 
         maxOutputDelay="00:00:07"/> 
      </pollingDuplexHttpBinding> 

<endpoint address="Duplex" 
          binding="pollingDuplexHttpBinding" 
          bindingConfiguration="multipleMessagesPerPollPollingDuplexHttpBinding" 
          contract="ProActive.Domain.Interfaces.IDuplexService"/> 

你看到有這樣的合同 -

[ServiceContract(Name = "IDuplexService", CallbackContract = typeof(IDuplexClient))] 
    public interface IDuplexServiceAsync 
    { 
     [OperationContract(AsyncPattern = true)] 
     IAsyncResult BeginConnect(int userId, AsyncCallback callback, object asyncState); 

     void EndConnect(IAsyncResult result); 
    } 

[ServiceContract] 
public interface IDuplexClient 
{ 
    [OperationContract(IsOneWay = true)] 
    void Refresh(); 
} 

這似乎是舉辦得很好,但我不是100%確定那個。

我的客戶端代碼看起來是這樣的 -

public class client : IDuplexClient 
{ 
    #region IDuplexClient Members 

    public void Refresh() 
    { 

    } 

    #endregion 
} 



public someOtherClass 
    { 
var binding = new PollingDuplexHttpBinding(); 
      binding.DuplexMode = PollingDuplexMode.MultipleMessagesPerPoll; 

      var address = new EndpointAddress("http://" + ConfigService.ServerName + "/Service.svc/Duplex/"); 

      var factory = new DuplexChannelFactory<IDuplexServiceAsync>(
       new InstanceContext(new client()), binding).CreateChannel(address); 
      factory.BeginConnect(0, new AsyncCallback((result) => 
       { 
        factory.EndConnect(result); 

       }), null); 

    } 

我得到一個ContractFilter不匹配的問題,當我跨過「factory.EndConnect(結果)」,但我不明白爲什麼。很明顯,在服務器上,我實現了異步接口的同步版本(所以只是連接而不是開始/終止連接),但這是我能想到的唯一一個在這裏存在不匹配合同的地方。

我真的把我的頭髮拉出來了......我已經禿頂了!任何幫助將非常感激。

在此先感謝。

回答

2

請通過顯式地設置命名空間的服務接口試試吧,你不應該有錯配的問題,因爲在客戶端和服務器不同的CLR命名空間。

[ServiceContract(Name = "IClient", Namespace = "http://your.namespace")] 
public interface IClient 
{ 
    [OperationContract(IsOneWay = true)] 
    void DoSomething(); 

    [OperationContract(IsOneWay = true)] 
    void DoSomethingElse(); 
} 

[ServiceContract(Name = "IServer", Namespace = "http://your.namespace", CallbackContract = typeof(IClient))] 
public interface IServer 
{ 
#if !SILVERLIGHT 
    [OperationContract] 
    string Operation1(string userName); 

    [OperationContract] 
    int Operation2(int x, int y); 
#else 
    [OperationContract(AsyncPattern = true)] 
    IAsyncResult BeginOperation1(string userName, AsyncCallback callback, object state); 
    string EndOperation1(IAsyncResult asyncResult); 

    [OperationContract(AsyncPattern = true)] 
    IAsyncResult BeginOperation2(int x, int y, AsyncCallback callback, object state); 
    int EndOperation2(IAsyncResult asyncResult); 
#endif 
} 
0

而且千萬要記得從4.0.0.0該版本更改爲5.0.0.0,因爲你正在使用SL 5(我想您已經從C加載正確的System.ServiceModel.PollingDuplex裝配:\ Program Files文件( 86)\微軟的SDK \ Silverlight的\ V5.0 \庫\服務器)