WCF服务超时错误? [英] WCF Service Timeout Error?

查看:489
本文介绍了WCF服务超时错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样同时使用C#和VB进口擅长的数据库,通过WCF服务的场景。而我使用WCF basicHttpBinding的。

工作流程

Excel的是有500条记录。我有在服务中插入查询。我到的数据集(在C#和VB.Net)转换Excel中的记录,那么我传递同一数据集用于插入使用每个语句的数据库服务(让我知道,如果它混淆)。在此之后,我试图显示插入记录的GridView这是在UI(在这里,问题就来了)。

问题是:

当我上传的excel表,I'getting错误象下面,

套​​接字连接被中止。这可能是一个错误处理您的信息或接收超时造成的远程主机,或潜在的网络资源问题被超过。本地套接字超时是00:09:59.9989999 ---> System.Net.Sockets.SocketException:现有的连接被强行关闭远程主机....

上面的错误是在客户端应用程序(UI)显示。但是(从Excel)中的数据仍然插入数据库作为幕后。

我试过是:

我曾尝试下面的东西,


  1. 我试图增加发送超时(如00:20:00)的服务Web配置文件,然​​后我反映在客户端应用程序相同的文件,但没有任何反应的价值观正在采取默认的超时时间。 (我相信,从configuration.svcinfo =>在serializedValue,发送超时时间为00:10:00)。

  2. 我试图增加maxreceivedMessageSize,如前所述MAXBUFFERSIZE,maxBufferPoolSize [这里]。 ( HTTP://www.$c$cproject.com/Questions/ 633699 /编程异常WCF )。但是什么都没有发生。

注意:它的工作完美,当我插入一条记录

和其他的障碍是,这是我的机器发生。但如果我尝试在我朋友的机器同样的事情,我能得到500条记录没有任何错误。

WCF服务code为插入:

注意: myds 是用于保存从Excel工作表中的记录数据集

 如果myds.Tables.Count> 0,则
            如果myds.Tables(0).Rows.Count> 0,则
                  对于每个医生在myds.Tables(0).Rows
                       InsertNewLog(用户ID,GNO,pnumber)
                  下一个
            万一
万一私人小组InsertNewLog(用户ID作为字符串,GNO作为的Int32,pnumber作为字符串)
   昏暗Oraclecon作为新的OracleConnection(System.Configuration.ConfigurationManager.AppSettings(的ConnectionString))
    昏暗的事务作为OracleTransaction    Oraclecon.Open()
    交易= Oraclecon.BeginTransaction(IsolationLevel.ReadCommitted)    昏暗myCMD作为新的OracleCommand(插入Log_table(与& _
         USER_ID,与& _
         GROUP_No,与& _
         PRO_No)值(:p_userid,:p_groupno,:p_pronumber)
    myCMD.Connection = Oraclecon    昏暗p_userid作为的OracleParameter =新的OracleParameter()
    p_userid.OracleDbType = OracleDbType.Varchar2
    p_userid.Value用户ID =
    myCMD.Parameters.Add(p_userid)    昏暗p_groupno作为的OracleParameter =新的OracleParameter()
    p_groupno.OracleDbType = OracleDbType.Int32
    p_groupno.Value = groupnbr
    myCMD.Parameters.Add(p_groupno)    昏暗p_pronumber作为的OracleParameter =新的OracleParameter()
    p_pronumber.OracleDbType = OracleDbType.Varchar2
    p_pronumber.Value = pronumber
    myCMD.Parameters.Add(p_pronumber)
    尝试
        myCMD.ExecuteNonQuery()
        器transaction.commit()
    捕捞副产品√
        抛出新的异常(x.ToString())
        transaction.Rollback()
        退出小组
    最后
        Oraclecon.Close()
        Oraclecon.Dispose()
    结束Try
结束小组


解决方案

有WCF中的配置文件数超时选项。我通常在config文件的部分设置所有的人都在客户端和服务器端:

 <绑定名称=defaultBinding
         closeTimeout =00:01:00
         openTimeout =00:01:00
         receiveTimeout =00:01:00
         的SendTimeout =00:01:00>
      <启用的ReliableSession =真正的inactivityTimeout =00:01:00/>
< /&结合GT;

如果你不使用的ReliableSession,那么就删除行

 <启用的ReliableSession =真正的inactivityTimeout =00:01:00/>

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

这篇关于WCF服务超时错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆