Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Not able to download the files

Hi All,

In my application Iam using a webservice to downlad the html, audio and video files from the broadcast server and save it in the relay server after creating the folder, but the file is not getting created and also not able to download the files and iam getting Event 1309 warning stating There is an Internal server error(500). Here is the code below and do help me on the same :


Private Sub RelayRemoteFile(ByRef context As HttpContext, ByVal strFileName As String)
Dim strSaveAsFileNameWithPath As String = ConfigurationManager.AppSettings("FileEncryptFolder") + strFileName
Const ChunkSize As Integer = 10000
Dim iStream As System.IO.Stream = Nothing
Dim iBroadcastStream As System.IO.Stream = Nothing
'Dim bytesFileChunk As Byte()
Dim FileSize As Integer = 0
'Dim Buffer(ChunkSize) As Byte


Dim strMutexName As String = strFileName

Dim strProxyURL As String = String.Empty
Dim iProxyPort As Integer
Dim sCompanyID As String = context.Request.QueryString("CID")
Dim BroadcastServerURI As String = ConfigurationManager.AppSettings("BroadcastServerURI") + strFileName + "&CID=" + sCompanyID
If strSaveAsFileNameWithPath.Contains("[COMPANYID]") Then
strSaveAsFileNameWithPath = strSaveAsFileNameWithPath.Replace("[COMPANYID]", sCompanyID)
End If

If Not ConfigurationManager.AppSettings.Item("ProxyURL") Is Nothing Then
strProxyURL = ConfigurationManager.AppSettings.Item("ProxyURL").ToString.Trim
End If
If Not ConfigurationManager.AppSettings.Item("ProxyPort") Is Nothing Then
iProxyPort = CInt(ConfigurationManager.AppSettings.Item("ProxyPort").ToString.Trim)
End If

'RelayRemoteFile can create a RACE condition as such use mutex to block subsecutive calls
Using mutex As New Mutex(False, strMutexName)
mutex.WaitOne()
Dim readLen As Integer = 0
Dim ncAuthorize As NetworkCredential = CredentialCache.DefaultNetworkCredentials 'New NetworkCredential("Username", "Password", "Domain")
Dim ohttpWebRequest As HttpWebRequest = DirectCast(WebRequest.Create(BroadcastServerURI), HttpWebRequest)
If (Not String.IsNullOrEmpty(strProxyURL)) Then
objProxy = New WebProxy(strProxyURL, iProxyPort)
objProxy.Credentials = CredentialCache.DefaultNetworkCredentials
ohttpWebRequest.Proxy = objProxy
End If

ohttpWebRequest.Credentials = ncAuthorize
Dim ohttpWebResponse As WebResponse = ohttpWebRequest.GetResponse()
Dim Buffer(ChunkSize) As Byte
Using responseStream As Stream = ohttpWebResponse.GetResponseStream()
Using oStream As Stream = File.Create(strSaveAsFileNameWithPath)
While True
readLen = responseStream.Read(Buffer, 0, Buffer.Length)
If readLen = 0 Then Exit While ' EoF
oStream.Write(Buffer, 0, readLen)
End While
End Using
End Using

RelayLocalFile(context, strSaveAsFileNameWithPath)

mutex.ReleaseMutex()
End Using

End Sub
Sign In or Register to comment.