WCF超时并且没有响应请求

时间:2014-05-27 08:41:41

标签: asp.net wcf iis

WCF超时问题

我有一个非常简单的WCF和BasicHTTPBinding 它返回一个XMLElement,它是一个转换的数据集。返回的数据仅包含大约1500行,宽13列。 WCF的设置位于Windows 2008计算机上的IIS 7.5中托管的专用服务器上。 客户端的设置是在Windows 2008计算机上的IIS 7.5中托管的专用Web服务器。

调用WCF服务的网站位于不同的计算机上,该计算机属于工作组但不属于域。 (它位于不同的位置,具有安全的VPN隧道) 我已经用尽了服务器和客户端上的绑定设置和超时限制的所有选项。

我试过了:

  • 在客户端和服务器上增加maxReceivedMessageSize
  • 增加了客户端和服务器上的maxItemsInObjectGraph
  • 在服务器和客户端上使用WCF跟踪,没有显示为故障
  • 增加了客户端和服务器的超时时间。
  • 可以使用ping从Web服务器计算机上看到WCFmachine。我也尝试使用IP地址而不是名称,因此不需要进行DNS查找。

问题是数据不会一直返回给客户端。有时它可以即时工作,有时它会在短时间后返回数据,但大多数时候会返回如下错误信息:

System.Exception:此流不支持超时。

或者像这样:

System.ServiceModel.CommunicationException:底层连接已关闭:服务器已关闭预期保持活动状态的连接。 ---> System.Net.WebException:底层连接已关闭:服务器已关闭预期保持活动状态的连接。 ---> System.IO.IOException:无法从传输连接读取数据:远程主机强制关闭现有连接。 ---> System.Net.Sockets.SocketException:远程主机强制关闭现有连接

注意:需要注意的最重要事项是,此操作系统100%的工作时间来自与WCF计算机位于同一域的网络服务器。

以下是我正在使用的完整设置:

客户端配置:

<system.serviceModel>
  <bindings>
    <basicHttpBinding>
      <binding name="BasicHttpBinding_IOrderListSvc" maxReceivedMessageSize="2147483647" />
    </basicHttpBinding>
  </bindings>

  <behaviors>
    <endpointBehaviors>
      <behavior name="SerializerObjectGraph">
        <dataContractSerializer maxItemsInObjectGraph="2147483646"/>
      </behavior>
    </endpointBehaviors>
  </behaviors>

  <client>
    <endpoint address="http://WCFmachine/AxceWCF.OrderListSvc.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IOrderListSvc" contract="OrderListSVC.IOrderListSvc" name="BasicHttpBinding_IOrderListSvc" behaviorConfiguration="SerializerObjectGraph" />
  </client>
</system.serviceModel>

服务器配置文件:

<system.serviceModel>
  <services>
    <service name="AxceWCF.OrderListSvc" behaviorConfiguration="SerializerTest">
      <endpoint address="" binding="basicHttpBinding" contract="AxceWCF.IOrderListSvc" behaviorConfiguration="SerializerObjectGraph" bindingConfiguration="BasicHttpBinding_IOrderListSvc">
        <identity>
          <dns value="localhost" />
        </identity>
      </endpoint>
      <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      <host>
        <baseAddresses>
          <add baseAddress="http://WCFmachine/AxceWCF.OrderListSvc.svc" />
        </baseAddresses>
      </host>
    </service>
  </services>

  <behaviors>
    <serviceBehaviors>
      <behavior name="SerializerTest">
        <serviceMetadata httpGetEnabled="True"/>
        <serviceDebug includeExceptionDetailInFaults="True"/>
        <dataContractSerializer maxItemsInObjectGraph="2147483646"/>
        <serviceThrottling maxConcurrentCalls="500" maxConcurrentSessions="500" maxConcurrentInstances="500" />
      </behavior>
    </serviceBehaviors>
    <endpointBehaviors>
      <behavior name="SerializerObjectGraph">
        <dataContractSerializer maxItemsInObjectGraph="2147483646"/>
      </behavior>
    </endpointBehaviors>
  </behaviors>

  <bindings>
    <basicHttpBinding>
      <binding name="BasicHttpBinding_IOrderListSvc" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" closeTimeout="01:50:00" openTimeout="01:50:00" sendTimeout="01:50:00" receiveTimeout="01:50:00" >
        <readerQuotas maxDepth="128" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
      </binding>
    </basicHttpBinding>  
  </bindings>
</system.serviceModel>

WCF服务:

<ServiceContract()>
Public Interface IOrderListSvc

<OperationContract()>
Function LoadOrderList(ByVal UserID As Integer) As XmlElement

End Interface

WCF续...

Public Function LoadOrderList(UserID As Integer) As Xml.XmlElement Implements IOrderListSvc.LoadOrderList

  Dim doc As New XmlDocument
  doc = OrderListDetails.LoadOrderList(UserID)

  Return doc.DocumentElement
End Function

返回数据的实际功能

Public Function LoadOrderList(ByVal UserID As Integer) As XmlDocument

        Using cConn As Connection = CreateDBConnection()
            cConn.Open()

            Dim strSQL As New System.Text.StringBuilder()

            strSQL.Append("SELECT O.Orderno, O.OrderDate, O.Quantity, o.assetTypeClassID, o.PartyID, o.AssetTypeID, o.PartNumber, o.item, o.Stock, o.SPExcl, o.Maker, o.AssetTypeClassName, o.Obsolete ")
            strSQL.Append("FROM Orders o ")
            strSQL.Append("WHERE O.OrderDate > dateadd(YEAR, -5, getDate() AND (o.UserID = '" & UserID & "') ")

            strSQL.Append("ORDER BY O.OrderDate ")

            Dim ds As New DataSet
            Dim dt As DataTable = cConn.ExecuteTable(strSQL.ToString)

            dt.TableName = "OrderList"
            ds.Merge(dt)

            Dim dsXML As New XmlDocument
            dsXML.LoadXml(ds.GetXml)

            Return dsXML

       End using

End Function

致电WCF返回结果:

Public Function TestOrderList(ByVal UserID As Integer) As DataTable

    Dim wsResults As XmlElement = Nothing
    Dim client As OrderListSVC.OrderListSvcClient = Nothing

    Try

        client = New OrderListSVC.OrderListSvcClient

        wsResults = client.LoadOrderList(UserID)

        DirectCast(client, ICommunicationObject).Close()

    Catch ex As Exception

        Throw New Exception(ex.Message, ex.InnerException)

    Finally

        If client IsNot Nothing Then
            DirectCast(client, ICommunicationObject).Abort()
        End If

        Return Nothing

    End Try

End Function

0 个答案:

没有答案