我将NetTcpBinding与Streamed TransferMode一起使用。现在,我尝试实现双工回调,但收到错误消息。是否可以将NetTcpBinding与Streamed TransferMode一起使用,并使用(双工)回调服务协定?
背景:
-我使用NetTcpBinding,因为它速度很快,而且没有nat问题
-我使用流式传输模式,因为我也传输大文件。
配置:
<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>
合约:
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);
}
设置transferMode =“ Streamed”时出现错误
合同要求使用双工,但是不支持“ NetTcpBinding”绑定
或没有正确配置以支持它。
每个人都可以建议谢谢
最佳答案
在客户端代码中,确保使用DuplexChannelFactory创建到服务器的通道:
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();
}
}
[编辑]自动生成的服务引用的代理应扩展DuplexClientBase。
关于c# - WCF,NetTcpBinding,流传输模式可以是双工吗?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12120351/