2011-02-24 73 views
0

私は、次のコードWCFタイムアウト問題

public bool StartWCF() 
    { 
     try 
     { 
      // Select the first entry. I hope it's this maschines IP 
      // IPAddress _ipAddress = ips.AddressList[0]; 
      var ipAddress = new IPAddress(new byte[] { 127, 0, 0, 1 }); 

      // Create the url that is needed to specify where the service should be started 
      this.m_UrlMetaServiceComm = "net.tcp://" + ipAddress + ":8000/VSMDBCommunication"; 
      this.m_UrlMetaServicePart = "net.tcp://" + ipAddress + ":8000/VSMDBPartType"; 

      string endPointAddrComm = this.m_UrlMetaServiceComm; 
      var tcpBindingComm = new NetTcpBinding 
       { 
        TransactionFlow = false, 
        MaxReceivedMessageSize = 20000000, 
        MaxBufferSize = 20000000, 
        MaxBufferPoolSize = 20000000, 
        ReaderQuotas = { MaxNameTableCharCount = 20000000 }, 
        OpenTimeout = new TimeSpan(0, 5, 0), 
        SendTimeout = new TimeSpan(0, 5, 0), 
        CloseTimeout = new TimeSpan(0, 5, 0) 
       }; 
      tcpBindingComm.Security.Transport.ProtectionLevel = ProtectionLevel.EncryptAndSign; 
      tcpBindingComm.Security.Transport.ClientCredentialType = TcpClientCredentialType.Windows; 
      tcpBindingComm.Security.Mode = SecurityMode.None; 

      var endpointAddressComm = new EndpointAddress(endPointAddrComm); 
      this.m_ChannelCommunication = ChannelFactory<IVSMDBCommunication>.CreateChannel(
       tcpBindingComm, endpointAddressComm); 
      ((IContextChannel)m_ChannelCommunication).OperationTimeout = new TimeSpan(0, 5, 0); 
      string endPointAddrPart = this.m_UrlMetaServicePart; 
      var tcpBindingPart = new NetTcpBinding 
       { 
        TransactionFlow = false, 
        MaxReceivedMessageSize = 20000000, 
        MaxBufferSize = 20000000, 
        MaxBufferPoolSize = 20000000, 
        ReaderQuotas = { MaxNameTableCharCount = 20000000 }, 
        OpenTimeout = new TimeSpan(0, 5, 0), 
        SendTimeout = new TimeSpan(0, 5, 0), 
        CloseTimeout = new TimeSpan(0, 5, 0) 
       }; 
      tcpBindingPart.Security.Transport.ProtectionLevel = ProtectionLevel.EncryptAndSign; 
      tcpBindingPart.Security.Transport.ClientCredentialType = TcpClientCredentialType.Windows; 
      tcpBindingPart.Security.Mode = SecurityMode.None; 

      var endpointAddressPart = new EndpointAddress(endPointAddrPart); 
      this.m_ChannelPartTypes = ChannelFactory<IVSMDBPartType>.CreateChannel(
       tcpBindingPart, endpointAddressPart); 
      ((IContextChannel)m_ChannelPartTypes).OperationTimeout = new TimeSpan(0, 5, 0); 
      return true; 
     } 
     catch (CommunicationObjectFaultedException faultEx) 
     { 
      // System.Diagnostics.Trace.TraceError(faultEx.ToString()); 
      Console.WriteLine("An unknown exception was received. " + faultEx.Message + faultEx.StackTrace); 
      Console.Read(); 
      return false; 
     } 
     catch (EndpointNotFoundException endEx) 
     { 
      // System.Diagnostics.Trace.TraceError(endEx.ToString()); 
      Console.WriteLine("An unknown exception was received. " + endEx.Message + endEx.StackTrace); 
      Console.Read(); 
      return false; 
     } 
    } 

を持っており、基本的なプロセスは、分以上かかるとき、私は時折、次のエラーが発生します。

メッセージ: net.tcpに送信

この要求操作://127.0.0.1:8000/VSMDBCommunication 構成されたタイムアウト(午前0時01分00秒)以内に応答を受信しませんでした。この操作に割り当てられた時間が の場合、 のタイムアウト時間の一部が になっている可能性があります。これは、 サービスがまだ 操作を処理しているか、またはサービスが の返信メッセージを送信できなかったためです。 (OperationTimeoutプロパティを設定 チャネル/ IContextChannelへのプロキシと をキャストすることにより) 操作のタイムアウトを増やすことを検討し、サービスが クライアントに接続することが可能であることを確認してください。

このエラーを回避する方法とは異なる方法でチャネルをキャストするにはどうすればいいですか。基本的な要求が計算に1分以上かかることがあるためです。

答えて

0

ReceiveTimeoutプロパティも設定してみてください。

+0

これは問題を解決していないようです。 – PlTaylor

2

これはあなたのエラーを削除します

client.InnerChannel.OperationTimeout = TimeSpan.FromMinutes(10); 

としてクライアントの動作時間を設定します。

+0

クライアントはどこですか?クライアントは何ですか? – Stephane