简体   繁体   English

WCF服务超时错误?

[英]WCF Service Timeout Error?

I have a scenario like importing excel in to database through WCF Service using both C# and VB. 我有一个场景,例如使用C#和VB通过WCF服务将excel导入数据库。 And I'm using WCF Basichttpbinding. 我正在使用WCF Basichttpbinding。

Work Flow 工作流程

The excel is having 500 records. Excel具有500条记录。 I'm having an Insert query in service. 我在服务中有一个插入查询。 I'm Converting Excel records in to dataset(in C# and VB.Net), then I'm passing the same dataset to service for insertion into database using for each statement(Let me know if it confuse). 我将Excel记录转换为数据集(在C#和VB.Net中),然后将相同的数据集传递给服务,以便使用每个语句插入数据库(让我知道是否混淆)。 After this, I'm trying to display the inserted records to gridview which is in UI(Here the problem comes). 在此之后,我试图将插入的记录显示到UI中的gridview(这是问题所在)。

Problem is: 问题是:

When I'm uploading the excel sheet, I'getting an error like below, 当我上传Excel工作表时,出现如下错误,

The Socket Connection was aborted. 套接字连接已中止。 This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue. 这可能是由于处理您的消息时出错,远程主机超出了接收超时或潜在的网络资源问题引起的。 Local socket timeout was 00:09:59.9989999 --->System.Net.Sockets.SocketException: Existing Connection was forcibly closed by the remote host .... 本地套接字超时为00:09:59.9989999 ---> System.Net.Sockets.SocketException:现有连接被远程主机强行关闭....

The above error is displaying in Client Application(UI). 上面的错误显示在客户端应用程序(UI)中。 But the data(from excel) are still inserting into database as behind the scene. 但是(来自excel的)数据仍在后台插入数据库中。

What I tried is: 我试过的是:

I have tried below things, 我在下面尝试过

  1. I tried to increase send timeout(as 00:20:00) in Service Web config file, then I reflected the same file in Client Application but nothing happens as the values are taking default Timeout. 我尝试增加Service Web配置文件中的发送超时(如00:20:00),然后在客户端应用程序中反映了相同的文件,但是由于值采用默认超时,因此没有任何反应。 (I believe, from configuration.svcinfo => In serializedValue, Send timeout is 00:10:00). (我相信,来自configuration.svcinfo =>在serializedValue中,发送超时为00:10:00)。
  2. I tried Increasing the maxreceivedMessageSize, maxBufferSize, maxBufferPoolSize as mentioned [here]. 我尝试按[here]所述增加maxreceivedMessageSize,maxBufferSize,maxBufferPoolSize。 ( http://www.codeproject.com/Questions/633699/Socket-Exception-WCF ). http://www.codeproject.com/Questions/633699/Socket-Exception-WCF )。 But nothing happened. 但是什么也没发生。

Note: It's working perfectly when I'm inserting one record. 注意:当我插入一条记录时,它工作得很好。

And the other hurdle is, that this is happening in my machine. 另一个障碍是,这正在我的机器上发生。 But If I try the same thing in my friend's machine, I'm able to get the 500 records without any error. 但是,如果我在朋友的机器上尝试相同的操作,则可以毫无错误地获得500条记录。

WCF Service Code for Insertion: WCF插入服务代码:

Note : myds is dataset that holds the records from the excel sheet. 注意: myds是保存excel工作表中记录的数据集。

If myds.Tables.Count > 0 Then
            If myds.Tables(0).Rows.Count > 0 Then
                  For Each dr In myds.Tables(0).Rows
                       InsertNewLog(userid, gno, pnumber)
                  Next
            End If
End If

Private Sub InsertNewLog(userid As String, gno As Int32, pnumber As String)
   Dim Oraclecon As New OracleConnection(System.Configuration.ConfigurationManager.AppSettings("ConnectionString"))
    Dim transaction As OracleTransaction

    Oraclecon.Open()
    transaction = Oraclecon.BeginTransaction(IsolationLevel.ReadCommitted)

    Dim myCMD As New OracleCommand("insert into Log_table( " & _
         " USER_ID, " & _
         " GROUP_No, " & _
         " PRO_No" ) values (:p_userid,:p_groupno, :p_pronumber)
    myCMD.Connection = Oraclecon

    Dim p_userid As OracleParameter = New OracleParameter()
    p_userid.OracleDbType = OracleDbType.Varchar2
    p_userid.Value = userid
    myCMD.Parameters.Add(p_userid)

    Dim p_groupno As OracleParameter = New OracleParameter()
    p_groupno.OracleDbType = OracleDbType.Int32
    p_groupno.Value = groupnbr
    myCMD.Parameters.Add(p_groupno)

    Dim p_pronumber As OracleParameter = New OracleParameter()
    p_pronumber.OracleDbType = OracleDbType.Varchar2
    p_pronumber.Value = pronumber
    myCMD.Parameters.Add(p_pronumber)
    Try
        myCMD.ExecuteNonQuery()
        transaction.Commit()
    Catch x
        Throw New Exception(x.ToString())
        transaction.Rollback()
        Exit Sub
    Finally
        Oraclecon.Close()
        Oraclecon.Dispose()
    End Try
End Sub

There are several"timeout" options in WCF config files. WCF配置文件中有多个“超时”选项。 I'm usually set all of them at client and server side in section of .config file: 我通常在.config文件的部分中将它们全部设置在客户端和服务器端:

<binding name="defaultBinding" 
         closeTimeout="00:01:00" 
         openTimeout="00:01:00" 
         receiveTimeout="00:01:00" 
         sendTimeout="00:01:00">
      <reliableSession enabled="true" inactivityTimeout="00:01:00" />
</binding>

If you don't use reliableSession , then just remove line 如果您不使用可靠的会话,则只需删除行

<reliableSession enabled="true" inactivityTimeout="00:01:00" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM