我正在编写一个由 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 不匹配问题,但我不明白为什么。显然,在服务器上我正在实现异步接口的同步版本(所以只是连接而不是开始/结束连接),但这是我能想到的唯一地方,这里有一个不匹配的合同。
我现在真的要拔头发了……我已经秃了!任何帮助将非常感激。
提前致谢。