2

I'm uses NetTcpBinding with Streamed TransferMode. Now I tried to achieve a callback as duplex but I got error message. It is possible to use NetTcpBinding with Streamed TransferMode and use (duplex) callback service contract? The background: - I use NetTcpBinding because it is fast and there's no nat issue - I use streamed mode because I tranfers big files as well.

the config:

 <netTcpBinding>
    <binding name="DuplexBinding" transferMode="Streamed"
                closeTimeout="00:10:00"  openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00"  transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="104857600" maxReceivedMessageSize="104857600"
             >
      <readerQuotas maxDepth="104857600" maxStringContentLength="104857600" maxArrayLength="104857600" maxBytesPerRead="104857600" maxNameTableCharCount="104857600"/>
      <reliableSession enabled="true" ordered="true" inactivityTimeout="00:10:00"/>
      <security mode="None" />
    </binding>
  </netTcpBinding>

the contract:

IMyDataService.cs

   [ServiceContract(CallbackContract = typeof(INotifyCallback))]
    public interface IMyDataService
    {
        [OperationContract(ProtectionLevel = System.Net.Security.ProtectionLevel.None)]
        [FaultContract(typeof(MyFaultException))]
        [FaultContract(typeof(MyUserAlreadyLoggedInFaultException))]
        [FaultContract(typeof(AuthorizationFaultException))]
        Guid Authenticate(Guid clientID, string userName, string password, bool forceLogin);
    }


INotifyCallback.cs

    public interface INotifyCallback
    {
        [OperationContract(IsOneWay = true)]
        void ShowMessageBox(string message);
    }

i have get error whent set transferMode="Streamed"

Contract requires Duplex, but Binding 'NetTcpBinding' doesn't support it or isn't configured properly to support it.

everyone can suggest thanks

1 Answers1

1

In your client code, make sure you're using DuplexChannelFactory to create the channel to the server:

INotifyCallback callbackObject = new NotifyCallbackImpl(); //your concrete callback class
var channelFactory = new DuplexChannelFactory<IMyDataServce>(callbackObject); //pick your favourite constructor!
IMyDataService channel = channelFactory.CreateChannel();
try {
    var guid = channel.Authenticate(....);
    //... use guid...
} finally {
    try {
        channel.Close();
    } catch (Exception) {
        channel.Abort();
    }
}

[Edit] The proxy of an auto-generated service reference should extend DuplexClientBase.

EthanB
  • 4,239
  • 1
  • 28
  • 46
  • 1
    you are misunderstand my question. my problem is current server not run with config when i set attribute transferMode="Streamed", if is remove it server run but i want use large file upload should transferMode="Streamed" is good choose – Nguyễn Văn Thắng Aug 25 '12 at 09:34
  • yes, with config atrribute transferMode="Streamed", default it set transferMode="Buffer" but in my case use with dublex it problems – Nguyễn Văn Thắng Aug 25 '12 at 09:40
  • 1
    [This answer](http://stackoverflow.com/questions/2005020/nettcpbinding-with-streaming-and-session) mentions some of the issues with ordered messages, callbacks, and streaming. (Pick any two of those and it would work--not all three at the same time). With streaming enabled, the duplex channel won't work. Sorry. – EthanB Aug 25 '12 at 09:43
  • Possible work-arounds include: using two separate contracts/channels (one streaming, one not) and/or refactoring out the callback. – EthanB Aug 25 '12 at 09:55
  • you are suggest to detail more? that is great suggest. – Nguyễn Văn Thắng Aug 25 '12 at 10:00
  • All-in-all, it's probably not going to be an issue to go with Buffered. Run it, profile it, and if memory is an issue *and you know it's caused by buffering*, then you could try to implement something more complex. I'd stick with Buffered transfer mode for now, though. – EthanB Aug 25 '12 at 10:03
  • i do something with asynchronous to upload file. – Nguyễn Văn Thắng Aug 25 '12 at 10:12