读取文件时WCF System.OutOfMemoryException - 无流式传输

时间:2015-12-04 14:12:32

标签: wcf iis iis-7.5

我有一个WCF服务,它读取一个二进制文件,它的大小是4 908 292 108字节(4.57 GB),代码在我的本地机器上工作正常但是当我在IIS(7.5)中部署它时它开始抛出System.OutOfMemoryException。

我正在使用此代码阅读它:

Friend Function ClipRectangle(ByVal Extent As MetricRectangle) As List(Of ShelterFeatureLine)

    Dim FileStream As FileStream
    Dim Reader As BinaryReader
    Dim OutputList As List(Of ShelterFeatureLine)
    Dim OneBlockResult As ShelterFeatureLine

    FileStream = New FileStream(mFilename, FileMode.Open, FileAccess.Read)
    Reader = New BinaryReader(FileStream)

    OutputList = New List(Of ShelterFeatureLine)

    Try
        Do While Not Reader.BaseStream.Position >= Reader.BaseStream.Length
            OneBlockResult = ProcessOneBlock(Reader, Extent)

            If Not OneBlockResult Is Nothing Then
                OutputList.Add(OneBlockResult)
            End If
        Loop
    Catch ex As Exception
        Throw New Exception(ex.Message & vbNewLine & "Reader.BaseStream.Position=" & Reader.BaseStream.Position & "/" & Reader.BaseStream.Length)
    End Try

    Reader.Close()
    FileStream.Close()
    Reader.Dispose()
    FileStream.Dispose()

    Return OutputList

End Function


Function ProcessOneBlock(ByVal Reader As BinaryReader, ByVal Extent As MetricRectangle) As ShelterFeatureLine

    Dim Porosity As Double
    Dim Height As Double
    Dim CountOfPoints As Integer
    Dim PointIndexBaseOne As Integer
    Dim LocationX As Double
    Dim LocationY As Double
    Dim DoUseThisLine As Boolean
    Dim PointsBaseZero() As MetricCoordinate
    Dim OneShelterFeatureLine As ShelterFeatureLine


    Porosity = Reader.ReadDouble
    Height = Reader.ReadDouble
    CountOfPoints = Reader.ReadInt32
    DoUseThisLine = False
    ReDim PointsBaseZero(CountOfPoints - 1)
    For PointIndexBaseOne = 1 To CountOfPoints
        LocationX = Reader.ReadDouble
        LocationY = Reader.ReadDouble 
        PointsBaseZero(PointIndexBaseOne - 1).X = LocationX
        PointsBaseZero(PointIndexBaseOne - 1).Y = LocationY
        If DoesPointLieInRectangle(Extent, LocationX, LocationY) Then
            DoUseThisLine = True
        End If
    Next
    If DoUseThisLine Then
        OneShelterFeatureLine = New ShelterFeatureLine(PointsBaseZero)
        With OneShelterFeatureLine
            .Porosity = Porosity
            .Height = Height
        End With
    End If

    If Not OneShelterFeatureLine Is Nothing Then
        Return OneShelterFeatureLine
    Else
        Return Nothing
    End If


End Function

当我到达时总是得到异常:Reader.BaseStream.Position = 4256694484 of 4908292108 剩下651597624字节

我甚至尝试将文件拆分为两部分并调用两次ClipRectangle,但是在seconth文件中,虽然缺少651597624字节,但它会停止: Reader.BaseStream.Position =1860389640分之1208792016

任何人都可以看到任何错误或知道某些IIS设置负责解决此问题?

0 个答案:

没有答案