Click here to Skip to main content
15,897,891 members
Articles / Programming Languages / Visual Basic

Progress Indication while Uploading/Downloading Files using WCF

Rate me:
Please Sign up or sign in to vote.
4.92/5 (66 votes)
4 Feb 2009CPOL5 min read 514.6K   14.6K   244  
This article examines the implementation of upload and download functionality with progress indication (progress bar feature) using Windows Communication Foundation.
'------------------------------------------------------------------------------
' <auto-generated>
'     This code was generated by a tool.
'     Runtime Version:2.0.50727.1378
'
'     Changes to this file may cause incorrect behavior and will be lost if
'     the code is regenerated.
' </auto-generated>
'------------------------------------------------------------------------------

Option Strict Off
Option Explicit On


Namespace FileTransferClient
    
    <System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0"),  _
     System.ServiceModel.ServiceContractAttribute(ConfigurationName:="FileTransferClient.IFileTransferService")>  _
    Public Interface IFileTransferService
        
        'CODEGEN: Generating message contract since the operation UploadFile is neither RPC nor document wrapped.
        <System.ServiceModel.OperationContractAttribute(Action:="http://tempuri.org/IFileTransferService/UploadFile", ReplyAction:="http://tempuri.org/IFileTransferService/UploadFileResponse")>  _
        Function UploadFile(ByVal request As FileTransferClient.RemoteFileInfo) As FileTransferClient.UploadFileResponse
        
        'CODEGEN: Generating message contract since the wrapper name (DownloadRequest) of message DownloadRequest does not match the default value (DownloadFile)
        <System.ServiceModel.OperationContractAttribute(Action:="http://tempuri.org/IFileTransferService/DownloadFile", ReplyAction:="http://tempuri.org/IFileTransferService/DownloadFileResponse")>  _
        Function DownloadFile(ByVal request As FileTransferClient.DownloadRequest) As FileTransferClient.RemoteFileInfo
    End Interface
    
    <System.Diagnostics.DebuggerStepThroughAttribute(),  _
     System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0"),  _
     System.ServiceModel.MessageContractAttribute(WrapperName:="RemoteFileInfo", WrapperNamespace:="http://tempuri.org/", IsWrapped:=true)>  _
    Partial Public Class RemoteFileInfo
        
        <System.ServiceModel.MessageHeaderAttribute([Namespace]:="http://tempuri.org/")>  _
        Public FileName As String
        
        <System.ServiceModel.MessageHeaderAttribute([Namespace]:="http://tempuri.org/")>  _
        Public Length As Long
        
        <System.ServiceModel.MessageBodyMemberAttribute([Namespace]:="http://tempuri.org/", Order:=0)>  _
        Public FileByteStream As System.IO.Stream
        
        Public Sub New()
            MyBase.New
        End Sub
        
        Public Sub New(ByVal FileName As String, ByVal Length As Long, ByVal FileByteStream As System.IO.Stream)
            MyBase.New
            Me.FileName = FileName
            Me.Length = Length
            Me.FileByteStream = FileByteStream
        End Sub
    End Class
    
    <System.Diagnostics.DebuggerStepThroughAttribute(),  _
     System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0"),  _
     System.ServiceModel.MessageContractAttribute(IsWrapped:=false)>  _
    Partial Public Class UploadFileResponse
        
        Public Sub New()
            MyBase.New
        End Sub
    End Class
    
    <System.Diagnostics.DebuggerStepThroughAttribute(),  _
     System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0"),  _
     System.ServiceModel.MessageContractAttribute(WrapperName:="DownloadRequest", WrapperNamespace:="http://tempuri.org/", IsWrapped:=true)>  _
    Partial Public Class DownloadRequest
        
        <System.ServiceModel.MessageBodyMemberAttribute([Namespace]:="http://tempuri.org/", Order:=0)>  _
        Public FileName As String
        
        Public Sub New()
            MyBase.New
        End Sub
        
        Public Sub New(ByVal FileName As String)
            MyBase.New
            Me.FileName = FileName
        End Sub
    End Class
    
    <System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")>  _
    Public Interface IFileTransferServiceChannel
        Inherits FileTransferClient.IFileTransferService, System.ServiceModel.IClientChannel
    End Interface
    
    <System.Diagnostics.DebuggerStepThroughAttribute(),  _
     System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")>  _
    Partial Public Class FileTransferServiceClient
        Inherits System.ServiceModel.ClientBase(Of FileTransferClient.IFileTransferService)
        Implements FileTransferClient.IFileTransferService
        
        Public Sub New()
            MyBase.New
        End Sub
        
        Public Sub New(ByVal endpointConfigurationName As String)
            MyBase.New(endpointConfigurationName)
        End Sub
        
        Public Sub New(ByVal endpointConfigurationName As String, ByVal remoteAddress As String)
            MyBase.New(endpointConfigurationName, remoteAddress)
        End Sub
        
        Public Sub New(ByVal endpointConfigurationName As String, ByVal remoteAddress As System.ServiceModel.EndpointAddress)
            MyBase.New(endpointConfigurationName, remoteAddress)
        End Sub
        
        Public Sub New(ByVal binding As System.ServiceModel.Channels.Binding, ByVal remoteAddress As System.ServiceModel.EndpointAddress)
            MyBase.New(binding, remoteAddress)
        End Sub
        
        <System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)>  _
        Function FileTransferClient_IFileTransferService_UploadFile(ByVal request As FileTransferClient.RemoteFileInfo) As FileTransferClient.UploadFileResponse Implements FileTransferClient.IFileTransferService.UploadFile
            Return MyBase.Channel.UploadFile(request)
        End Function
        
        Public Sub UploadFile(ByVal FileName As String, ByVal Length As Long, ByVal FileByteStream As System.IO.Stream)
            Dim inValue As FileTransferClient.RemoteFileInfo = New FileTransferClient.RemoteFileInfo
            inValue.FileName = FileName
            inValue.Length = Length
            inValue.FileByteStream = FileByteStream
            Dim retVal As FileTransferClient.UploadFileResponse = CType(Me,FileTransferClient.IFileTransferService).UploadFile(inValue)
        End Sub
        
        <System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)>  _
        Function FileTransferClient_IFileTransferService_DownloadFile(ByVal request As FileTransferClient.DownloadRequest) As FileTransferClient.RemoteFileInfo Implements FileTransferClient.IFileTransferService.DownloadFile
            Return MyBase.Channel.DownloadFile(request)
        End Function
        
        Public Function DownloadFile(ByRef FileName As String, <System.Runtime.InteropServices.OutAttribute()> ByRef FileByteStream As System.IO.Stream) As Long
            Dim inValue As FileTransferClient.DownloadRequest = New FileTransferClient.DownloadRequest
            inValue.FileName = FileName
            Dim retVal As FileTransferClient.RemoteFileInfo = CType(Me,FileTransferClient.IFileTransferService).DownloadFile(inValue)
            FileName = retVal.FileName
            FileByteStream = retVal.FileByteStream
            Return retVal.Length
        End Function
    End Class
End Namespace

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
Luxembourg Luxembourg
Dimitris Papadimitriou is a Software Development Professional specialized in Microsoft technologies. He has been awarded with the Microsoft MVP award (Connected System Developer). He lives in Luxembourg. Read more in his personal web page.

Comments and Discussions