提问人:Harjit 提问时间:3/21/2023 更新时间:5/12/2023 访问量:39
WCF Rest 服务下载文件“信号量异常”
WCF Rest Service Download File "Semaphore Exception"
问:
我遇到了使用 WCF rest 序列从服务器下载文件的问题。在 localhost 上一切正常,但是当我从静态 ip 公开 api 时,远程计算机无法下载大文件 (500Mb)。
以下是我到目前为止的测试场景:
- 使用 webHttpBinding。
- 当 transferMode = “buffered” 时,文件正在传输,但 byteArraylength 除外。
- 当 transferMode = “streamed” 时,文件在远程浏览器上开始下载,但在服务器端之间停止,存在“信号量超时期限已过期”的例外。
服务合同
<ServiceContract>
Public Interface IService
<OperationContract()>
<WebGet(UriTemplate:="File/{Param}", ResponseFormat:=WebMessageFormat.Json, BodyStyle:=WebMessageBodyStyle.Bare)>
Function FileDownloadRequest(Param As String) As Stream
End Interface
<ServiceBehavior(InstanceContextMode:=InstanceContextMode.Single, ConcurrencyMode:=ConcurrencyMode.Multiple, UseSynchronizationContext:=False)>
Public Class RequestHandler
Implements IService
Private Function FileDownloadRequest(Param As String) As Stream Implements IService.FileDownloadRequest
Dim _FileName As String = RootFolder & "\" & Param
Try
ReqLogs.Add("<<-- Download request recieved for " & _FileName)
'
'Header Set For CORS
'
WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Origin", "*")
If File.Exists(_FileName) Then
WebOperationContext.Current.OutgoingResponse.Headers("Content-Disposition") = "attachment; filename=" + "Report Data.csv"
WebOperationContext.Current.OutgoingResponse.ContentType = "application/octet-stream"
WebOperationContext.Current.OutgoingResponse.StatusCode = Net.HttpStatusCode.OK
Dim _FStream As New FileStream(_FileName, FileMode.Open, FileAccess.Read)
WebOperationContext.Current.OutgoingResponse.ContentLength = _FStream.Length
ReqLogs.Add("<<-- Download processing..... ++ " & _FStream.Length.ToString)
Return _FStream
Else
ReqLogs.Add("---- File not found to download !!!")
Throw New Exception("File not found to download")
End If
Catch ex As Exception
ReqLogs.Add("Download event error: " & ex.Message)
WebOperationContext.Current.OutgoingResponse.StatusCode = Net.HttpStatusCode.InternalServerError
Return Nothing
End Try
End Function
End Class
答: 暂无答案
评论
maxReceivedMessageSize="67108864"