简体   繁体   中英

WCF Service Timeout Error?

I have a scenario like importing excel in to database through WCF Service using both C# and VB. And I'm using WCF Basichttpbinding.

Work Flow

The excel is having 500 records. 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). After this, I'm trying to display the inserted records to gridview which is in UI(Here the problem comes).

Problem is:

When I'm uploading the excel sheet, I'getting an error like below,

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 ....

The above error is displaying in Client Application(UI). But the data(from excel) are still inserting into database as behind the scene.

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. (I believe, from configuration.svcinfo => In serializedValue, Send timeout is 00:10:00).
  2. I tried Increasing the maxreceivedMessageSize, maxBufferSize, maxBufferPoolSize as mentioned [here]. ( 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.

WCF Service Code for Insertion:

Note : myds is dataset that holds the records from the excel sheet.

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. I'm usually set all of them at client and server side in section of .config file:

<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" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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