2012-08-25 56 views
2

我使用NetTcpBinding和Streamed TransferMode。現在我試圖實現一個回調作爲雙工,但我得到了錯誤信息。可以將NetTcpBinding與Streamed TransferMode結合使用並使用(雙工)回調服務契約? 背景: - 我使用NetTcpBinding,因爲它速度很快並且沒有nat問題 - 我使用流式傳輸模式,因爲我也傳輸大文件。WCF,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); 
    } 

我有得到錯誤了when設置transferMode = 「流」

合同要求雙面打印,但綁定 'NetTcpBinding的'不支持 它或未正確配置以支持它。

每個人都可以建議感謝

+0

您是否使用DuplexChannelFactory連接到服務器(或者只是一個ChannelFactory)? – EthanB

+0

我使用IMetadataExchange添加servicereferece並創建客戶端代理 –

回答

1

在您的客戶端代碼,請確保您使用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

+0

您誤解了我的問題。我的問題是當前服務器不運行配置當我設置屬性transferMode =「流」,如果是刪除它服務器運行,但我想用大文件上傳應transferMode =「流」很好選擇 –

+0

服務器端問題。得到它了。 – EthanB

+0

是的,與配置atrribute transferMode =「流」,默認它設置transferMode =「緩衝區」,但在我的情況下使用dublex它的問題 –