سؤال

Service contract:

[ServiceContract(CallbackContract = typeof(IClientCallBackChannel),
SessionMode = SessionMode.Required)]
 public interface IServerService
 {
     [OperationContract(IsOneWay = true)]
      void foo();
 }

Client contract:

public interface IClientCallBackChannel
{
    [OperationContract(IsOneWay = false)]
    object DoCommand(Command command);
}


class ClientCallBackChannelImpl
{
    public object DoCommand(Command command)
    {
        // freezes service
        serverService.foo();

        // OK
        new Action(() =>
        {
             Thread.Sleep(1000);                          
             serverService.foo();                                          
        }
            ).BeginInvoke(null,null);

     }            
}

I have a duplex service and when I am calling a client method 'DoCommand' that inside that method there is a call to a Service method foo, my service freezes. If I call foo asynchronously it works fine, but I need the call to be synchronous.

هل كانت مفيدة؟

المحلول

I think the problem is that you need the DoCommand to return a value and so are not able to make it OneWay. If you think about this, this has to block your Service.

You can set the ConcurrencyMode of your ServiceBehavior to Multiple and this should work but IMHO it's not the best option.

As you have a two-way communication try sticking to OneWay-Methods - this will solve the problem and prevent you from difficult concurency problems with the above mentioned behaviour.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top