2

I have a WCF Service that is configured by net.tcp binding. I can reach the service by client and can call methods of it. Also I can reach the OperationContext.Current. Such as:

[ServiceContract(CallbackContract = typeof(IServiceCallback))]
public interface IService
{
    [OperationContract(IsOneWay = true)]
    void Register();
}

[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Multiple)]
    public class Service :IService
    {
        public void Register()
        {
             CallBacker.Client = OperationContext.Current.
                                 GetCallbackChannel<IServiceCallback>();

        }
    }

}

public class CallBacker 
{
   public static IServiceCallback Client { get; set; }

   public void Call(string message)
   {
       Client.Test(message);
   }
}

When the client calls the Register method of Service, I can see channel is stored on CallBacker.Client but when I call "Call" method of the CallBacker > Call(string message), the Client comes null.

The strange thing is when I set the service configuration from net.tcp to wsdualhttpbinding, it works perfect. Is there any different between net.tcp and wsdualhttpbinding that can cause this strange problem ?

Barış Velioğlu
  • 5,709
  • 15
  • 59
  • 105
  • Not sure what you mean by "set the service configuration" if the service exposes two endpoints (tcp, httpdual) you should be able to choose which one you use from the client and go back and forth between them. If you are actually changing the service then that may be the difference? – PatFromCanada Apr 07 '14 at 14:34

2 Answers2

1

It seems that the CallbackContract should be of type IServiceCallback [ServiceContract(CallbackContract = typeof(IServiceCallback))]

The below is the config for both wsDualHttpBinding and netTcpBinding

<services>
  <service behaviorConfiguration="behavior" name="WCFCallbackTry.Service1">
    <endpoint address="" binding="wsDualHttpBinding" bindingConfiguration="HttpEndPoint"
      contract="WCFCallbackTry.IService" name="HttpEndPoint"/>
    <endpoint address="net.tcp://localhost:8004/Service1.svc"  bindingConfiguration="BindingConfiguration" binding="netTcpBinding"
      contract="WCFCallbackTry.IService" name="NetTcpEndPoint"/>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:8018/Service1.svc"/>
      </baseAddresses>
    </host>
  </service>
</services>

Please also find the netTcpBinding used

<netTcpBinding>
    <binding name="BindingConfiguration" receiveTimeout="infinite" sendTimeout="10.00:00:00" maxBufferPoolSize="1073741824" maxBufferSize="1073741824" maxReceivedMessageSize="1073741824">
      <readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384"/>
      <reliableSession enabled="true" inactivityTimeout="01:00:00" ordered="true" />
    </binding>
  </netTcpBinding>

The CallBacker.Client holds the value of the CallBackContract while using netTcpBinding, and there does not seem to be any issue if the CallBackContract is changed to IServiceCallback

dera
  • 401
  • 2
  • 4
  • That was my mistake. While simplfing the question, I forgot it there. I fix it on the question. Thats not the real problem. – Barış Velioğlu Apr 09 '14 at 11:21
  • @RyuKaplan - It would be helpful if you post further details, like how do you make the callback call, binding configuration details, what client do you use to call the service etc. – dera Apr 10 '14 at 05:02
0

You are misunderstanding the implication of static here. In this context static would mean, be the same for every CallBacker instance. Then with your concurency.multiple multiple clients at the same time might use your callbacker.client to callback but the context won't be the one you expect. Drop the static and see if you get any errors in the log file then.

woutervs
  • 1,500
  • 12
  • 28