Nguyễn Văn Thắng
Nguyễn Văn Thắng

Reputation: 255

WCF, NetTcpBinding, Streamed transfer mode can be duplex?

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

Upvotes: 2

Views: 3539

Answers (1)

EthanB
EthanB

Reputation: 4289

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.

Upvotes: 1

Related Questions