PollingDuplexHttpBinding e DuplexChannelFactory - 'Incompatibilidade de ContractFilter no EndpointDispatcher'
-
13-11-2019 - |
Pergunta
Estou escrevendo um serviço duplex que será consumido por um cliente Silverlight 5.A configuração do meu servidor é assim (nos lugares certos, obviamente) –
<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"/>
O contrato que você vê aí é este -
[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();
}
Parece hospedar bem, mas não tenho 100% de certeza disso.
Meu código de cliente é assim -
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);
}
Estou tendo um problema de incompatibilidade de ContractFilter quando passo por 'factory.EndConnect(result)', mas não vejo por quê.Obviamente, no servidor, estou implementando a versão síncrona da interface Async (apenas Connect e não Begin/EndConnect), mas esse é o único lugar em que consigo pensar que existe um contrato incompatível aqui.
Estou realmente arrancando o cabelo agora... e já estou careca!Qualquer ajuda seria muito apreciada.
Desde já, obrigado.
Solução
Por favor, tente definindo explicitamente o nome e espaços para nome de suas interfaces de serviço, você não deverá ter problemas de incompatibilidade devido a diferentes namespaces CLR no cliente e no servidor.
[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
}
Outras dicas
E lembre-se de alterar essa versão de 4.0.0.0 para 5.0.0.0, já que você está usando SL 5 (e presumo que você carregou o assembly System.ServiceModel.PollingDuplex correto de c:\Program Files (x86)\Microsoft SDKs\Silverlight \v5.0\Bibliotecas\Servidor)