PollingDuplexHttpBinding and DuplexChannelFactory - 'ContractFilter mismatch at the EndpointDispatc



我正在编写一个将由Silverlight5客户端使用的双工服务。我的服务器配置看起来是这样的(显然在正确的地方)-

            <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(结果)"时,我遇到了ContractFilter不匹配的问题,但我不明白为什么。很明显,在服务器上,我正在实现异步接口的同步版本(所以只有Connect,而不是Begin/EndConnect),但这是我唯一能想到的存在不匹配约定的地方。

我现在真的很紧张。。。我已经秃顶了!如有任何帮助,我们将不胜感激。

提前谢谢。

请通过显式设置服务接口的名称命名空间来尝试,您不应该因为客户端和服务器中的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
}

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

相关内容

  • 没有找到相关文章

最新更新