gpt4 book ai didi

c# - WCF、NetTcpBinding、Streamed 传输模式可以双工吗?

转载 作者:太空宇宙 更新时间:2023-11-03 13:56:07 25 4
gpt4 key购买 nike

我将 NetTcpBinding 与 Streamed TransferMode 结合使用。现在我尝试将回调实现为双工,但收到错误消息。可以将 NetTcpBinding 与 Streamed TransferMode 一起使用并使用(双工)回调服务契约(Contract)吗?的背景:- 我使用 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>

契约(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);
}

设置 transferMode="Streamed"时出现错误

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

大家可以建议谢谢

最佳答案

在您的客户端代码中,确保您使用的是 DuplexChannelFactory创建到服务器的 channel :

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、Streamed 传输模式可以双工吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12120351/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com