[英]WCF, NetTcpBinding, Streamed transfer mode can be duplex?
我將NetTcpBinding與Streamed TransferMode一起使用。 現在,我嘗試實現雙工回調,但收到錯誤消息。 是否可以將NetTcpBinding與Streamed TransferMode一起使用,並使用(雙工)回調服務協定? 背景:-我使用NetTcpBinding,因為它運行速度很快,而且沒有問題。-我使用流傳輸模式,因為我也傳輸大文件。
配置:
<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 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.