【问题标题】:PollingDuplexHttpBinding and DuplexChannelFactory - 'ContractFilter mismatch at the EndpointDispatcher'PollingDuplexHttpBinding 和 DuplexChannelFactory - 'EndpointDispatcher 的 ContractFilter 不匹配'
【发布时间】:2012-02-27 11:33:16
【问题描述】:

我正在编写一个供 Silverlight 5 客户端使用的双工服务。我的服务器配置看起来像这样(显然在正确的位置)-

            <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);

    }

当我跨过“factory.EndConnect(result)”时遇到了 ContractFilter 不匹配问题,但我不明白为什么。显然,在服务器上我正在实现异步接口的同步版本(所以只是连接而不是开始/结束连接),但这是我能想到的唯一地方,这里存在不匹配的合同。

我现在真的要拔头发了……而且我已经秃了!任何帮助将不胜感激。

提前致谢。

【问题讨论】:

    标签: wcf silverlight-5.0 pollingduplexhttpbinding


    【解决方案1】:

    请通过显式设置服务接口的 namenamespaces 来尝试,您应该不会因为客户端中不同的 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
    }
    

    【讨论】:

      【解决方案2】:

      请记住将该版本从 4.0.0.0 更改为 5.0.0.0,因为您使用的是 SL 5(我假设您已从 c:\Program Files (x86)\Microsoft 加载了正确的 System.ServiceModel.PollingDuplex 程序集SDKs\Silverlight\v5.0\Libraries\Server)

      【讨论】:

        猜你喜欢
        • 2013-02-21
        • 1970-01-01
        • 2014-04-16
        • 2013-03-09
        • 2011-07-26
        • 2011-03-28
        • 2018-07-05
        • 2019-07-20
        • 1970-01-01
        相关资源
        最近更新 更多