Click here to Skip to main content
12,244,103 members (46,685 online)
Click here to Skip to main content

Stats

89.6K views
2.8K downloads
112 bookmarked
Posted

Saving Files Into Database Using .NET Web Services

, 3 Oct 2010 CPOL
In this article, I will show you how to save big files into database using .NET Web Service and how to monitor transfer status.
FileTransfer
FileTransferWebService
App_Data
FileTransferWebService.csproj.user
Properties
Properties
Service References
Web References
FileTransferWebService
FileTransfer.wsdl
Reference.map
WebServiceFileTransfer.suo
//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:2.0.50727.4927
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

// 
// This source code was auto-generated by Microsoft.VSDesigner, Version 2.0.50727.4927.
// 
#pragma warning disable 1591

namespace FileTransfer.FileTransferWebService {
    using System.Diagnostics;
    using System.Web.Services;
    using System.ComponentModel;
    using System.Web.Services.Protocols;
    using System;
    using System.Xml.Serialization;
    
    
    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Web.Services", "2.0.50727.4927")]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Web.Services.WebServiceBindingAttribute(Name="FileTransferSoap", Namespace="http://tempuri.org/")]
    public partial class FileTransfer : System.Web.Services.Protocols.SoapHttpClientProtocol {
        
        private System.Threading.SendOrPostCallback GetTempFilenameOperationCompleted;
        
        private System.Threading.SendOrPostCallback AppendToTempFileOperationCompleted;
        
        private System.Threading.SendOrPostCallback SaveFileIntoDatabaseOperationCompleted;
        
        private bool useDefaultCredentialsSetExplicitly;
        
        /// <remarks/>
        public FileTransfer() {
            this.Url = global::FileTransfer.Properties.Settings.Default.FileTransfer_FileTransferWebService_FileTransfer;
            if ((this.IsLocalFileSystemWebService(this.Url) == true)) {
                this.UseDefaultCredentials = true;
                this.useDefaultCredentialsSetExplicitly = false;
            }
            else {
                this.useDefaultCredentialsSetExplicitly = true;
            }
        }
        
        public new string Url {
            get {
                return base.Url;
            }
            set {
                if ((((this.IsLocalFileSystemWebService(base.Url) == true) 
                            && (this.useDefaultCredentialsSetExplicitly == false)) 
                            && (this.IsLocalFileSystemWebService(value) == false))) {
                    base.UseDefaultCredentials = false;
                }
                base.Url = value;
            }
        }
        
        public new bool UseDefaultCredentials {
            get {
                return base.UseDefaultCredentials;
            }
            set {
                base.UseDefaultCredentials = value;
                this.useDefaultCredentialsSetExplicitly = true;
            }
        }
        
        /// <remarks/>
        public event GetTempFilenameCompletedEventHandler GetTempFilenameCompleted;
        
        /// <remarks/>
        public event AppendToTempFileCompletedEventHandler AppendToTempFileCompleted;
        
        /// <remarks/>
        public event SaveFileIntoDatabaseCompletedEventHandler SaveFileIntoDatabaseCompleted;
        
        /// <remarks/>
        [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/GetTempFilename", RequestNamespace="http://tempuri.org/", ResponseNamespace="http://tempuri.org/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
        public string GetTempFilename() {
            object[] results = this.Invoke("GetTempFilename", new object[0]);
            return ((string)(results[0]));
        }
        
        /// <remarks/>
        public void GetTempFilenameAsync() {
            this.GetTempFilenameAsync(null);
        }
        
        /// <remarks/>
        public void GetTempFilenameAsync(object userState) {
            if ((this.GetTempFilenameOperationCompleted == null)) {
                this.GetTempFilenameOperationCompleted = new System.Threading.SendOrPostCallback(this.OnGetTempFilenameOperationCompleted);
            }
            this.InvokeAsync("GetTempFilename", new object[0], this.GetTempFilenameOperationCompleted, userState);
        }
        
        private void OnGetTempFilenameOperationCompleted(object arg) {
            if ((this.GetTempFilenameCompleted != null)) {
                System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));
                this.GetTempFilenameCompleted(this, new GetTempFilenameCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState));
            }
        }
        
        /// <remarks/>
        [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/AppendToTempFile", RequestNamespace="http://tempuri.org/", ResponseNamespace="http://tempuri.org/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
        public void AppendToTempFile(string tempFilename, [System.Xml.Serialization.XmlElementAttribute(DataType="base64Binary")] byte[] data) {
            this.Invoke("AppendToTempFile", new object[] {
                        tempFilename,
                        data});
        }
        
        /// <remarks/>
        public void AppendToTempFileAsync(string tempFilename, byte[] data) {
            this.AppendToTempFileAsync(tempFilename, data, null);
        }
        
        /// <remarks/>
        public void AppendToTempFileAsync(string tempFilename, byte[] data, object userState) {
            if ((this.AppendToTempFileOperationCompleted == null)) {
                this.AppendToTempFileOperationCompleted = new System.Threading.SendOrPostCallback(this.OnAppendToTempFileOperationCompleted);
            }
            this.InvokeAsync("AppendToTempFile", new object[] {
                        tempFilename,
                        data}, this.AppendToTempFileOperationCompleted, userState);
        }
        
        private void OnAppendToTempFileOperationCompleted(object arg) {
            if ((this.AppendToTempFileCompleted != null)) {
                System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));
                this.AppendToTempFileCompleted(this, new System.ComponentModel.AsyncCompletedEventArgs(invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState));
            }
        }
        
        /// <remarks/>
        [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/SaveFileIntoDatabase", RequestNamespace="http://tempuri.org/", ResponseNamespace="http://tempuri.org/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
        public void SaveFileIntoDatabase(string filename, string tempFilename) {
            this.Invoke("SaveFileIntoDatabase", new object[] {
                        filename,
                        tempFilename});
        }
        
        /// <remarks/>
        public void SaveFileIntoDatabaseAsync(string filename, string tempFilename) {
            this.SaveFileIntoDatabaseAsync(filename, tempFilename, null);
        }
        
        /// <remarks/>
        public void SaveFileIntoDatabaseAsync(string filename, string tempFilename, object userState) {
            if ((this.SaveFileIntoDatabaseOperationCompleted == null)) {
                this.SaveFileIntoDatabaseOperationCompleted = new System.Threading.SendOrPostCallback(this.OnSaveFileIntoDatabaseOperationCompleted);
            }
            this.InvokeAsync("SaveFileIntoDatabase", new object[] {
                        filename,
                        tempFilename}, this.SaveFileIntoDatabaseOperationCompleted, userState);
        }
        
        private void OnSaveFileIntoDatabaseOperationCompleted(object arg) {
            if ((this.SaveFileIntoDatabaseCompleted != null)) {
                System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));
                this.SaveFileIntoDatabaseCompleted(this, new System.ComponentModel.AsyncCompletedEventArgs(invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState));
            }
        }
        
        /// <remarks/>
        public new void CancelAsync(object userState) {
            base.CancelAsync(userState);
        }
        
        private bool IsLocalFileSystemWebService(string url) {
            if (((url == null) 
                        || (url == string.Empty))) {
                return false;
            }
            System.Uri wsUri = new System.Uri(url);
            if (((wsUri.Port >= 1024) 
                        && (string.Compare(wsUri.Host, "localHost", System.StringComparison.OrdinalIgnoreCase) == 0))) {
                return true;
            }
            return false;
        }
    }
    
    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Web.Services", "2.0.50727.4927")]
    public delegate void GetTempFilenameCompletedEventHandler(object sender, GetTempFilenameCompletedEventArgs e);
    
    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Web.Services", "2.0.50727.4927")]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    public partial class GetTempFilenameCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs {
        
        private object[] results;
        
        internal GetTempFilenameCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) : 
                base(exception, cancelled, userState) {
            this.results = results;
        }
        
        /// <remarks/>
        public string Result {
            get {
                this.RaiseExceptionIfNecessary();
                return ((string)(this.results[0]));
            }
        }
    }
    
    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Web.Services", "2.0.50727.4927")]
    public delegate void AppendToTempFileCompletedEventHandler(object sender, System.ComponentModel.AsyncCompletedEventArgs e);
    
    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Web.Services", "2.0.50727.4927")]
    public delegate void SaveFileIntoDatabaseCompletedEventHandler(object sender, System.ComponentModel.AsyncCompletedEventArgs e);
}

#pragma warning restore 1591

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)

Share

About the Author

Kanasz Robert
Architect The Staffing Edge & Marwin Cassovia Soft
Slovakia Slovakia
My name is Robert Kanasz and I have been working with ASP.NET, WinForms and C# for several years.
MCSD - Web Applications
MCSE - Data Platform
MCPD - ASP.NET Developer 3.5
- Web Developer 4
MCITP - Database Administrator 2008
- Database Developer 2008
MCSA - SQL Server 2012
MCTS - .NET Framework 3.5, ASP.NET Applications
- SQL Server 2008, Database Development
- SQL Server 2008, Implementation and Maintenance
- .NET Framework 4, Data Access
- .NET Framework 4, Service Communication Applications
- .NET Framework 4, Web Applications
MS - Programming in HTML5 with JavaScript and CSS3 Specialist

Open source projects: DBScripter - Library for scripting SQL Server database objects


Please, do not forget vote

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160426.1 | Last Updated 3 Oct 2010
Article Copyright 2010 by Kanasz Robert
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid