views:

611

answers:

2

I am building a website where i need a page where user can upload large video files, i have created WCF service with streaming but i am calling that WCF service from Button_Click event of web page.

I have used below mentioned article for WCF service creation

WCF Streaming

I have used streaming as it should be efficient and should not be buffered in memory of server.

Now questions

1) I am having doubts that the entire file is uploaded to the web server and then it is transferred to WCF Service server...if this is true then i am not getting advantage of streaming as well as iis and web server will be down very soon if user uploads large file or multiple user are uploading files con currently

2) Is there any other efficient way to do same operation with some other technique

Please help me ...

EDIT :

If I am not calling WCF Service method from ASP .Net code in that case also it is transferring bytes to the web server which i have checked with HTTPFox

I have checked above thing with upload control and putting one button on UI whose click event is bound to one method in code behind.

So, still i am having that confusion that how data is transferred

  1. Client Machine - Web Server (ASP .Net Application) - Service Server (WCF Service)
  2. Client Machine - Service Server (WCF Service)

NOTE : If i am putting a debug point on button_click and uploading 10 kb file it hits that in less then 1 sec. but if i am uploading 50 mb file then it is taking time.

I placed code of calling WCF service inside that button_click event

+2  A: 

Here is your best solution, I went the same route as you and concluded ftp is easier and works flawlessly. Here is some example code:

First get this library, works flawlessly:

http://www.freedownloadscenter.com/Programming/Components_and_Libraries/BytesRoad_NetSuit_Library.html

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.ServiceModel;
    using System.IO;
    using System.Configuration;
    using System.Collections.Specialized;
    using System.Drawing;
    using System.Drawing.Imaging;
    using System.Net;
    using BytesRoad.Net.Ftp;





    namespace GetMedia
    {
        class Program
        {

            static void Main(string[] args)
            {

                string strPath;
                string strThumbPath;
                string strThumbLocalPath;
                string strURLRoot;
                string strVideoFile;
                string strThumbfile;
                string strError;


                BizetDataDataContext db = new BizetDataDataContext();
                VCMediaDataContext db2 = new VCMediaDataContext();
                db.Connection.ConnectionString = Settings.Default.ConnectionString;
                db2.Connection.ConnectionString = Settings.Default.ConnectionString;

                //Temp Folder
                strPath = Settings.Default.TempFolder;
                strThumbLocalPath = Settings.Default.ThumbPath;

download video and thumb
            //then upload to mediaserver

                IQueryable<BizetInfo> custQuery =
                from bizet in db.BizetInfos
                where bizet.Path != null
                select bizet;

                foreach (BizetInfo objbizet in custQuery)
                {
                    //Grab filename and path


                    strVideoFile = Path.GetFileName(objbizet.Path).Replace("%20", "_").Replace("_medium", "").Replace(" ", "_");
                    strThumbfile = Path.GetFileName(objbizet.Path).Replace("%20", " ").Replace("_medium.wmv", ".mpg.png");
                    strURLRoot = objbizet.Path.Replace(Path.GetFileName(objbizet.Path), "");
                    strThumbPath = strURLRoot + strThumbfile;



                    strError = "";

                    try
                    {



                        wsViaCastMedia.MediaTransferSoapClient ws = new wsViaCastMedia.MediaTransferSoapClient();

                        System.Net.WebClient wc = new System.Net.WebClient();
                        //connect to Bizet
                        Console.WriteLine("Starting spotID: " + objbizet.SPOTID.ToString().Trim());
                        Console.WriteLine("connected to ws");
                        Console.WriteLine("Downloading Video File");

                        //Download  Video
                        wc.DownloadFile(objbizet.Path, strPath + strVideoFile);

                        //Download Thumb
                        Console.WriteLine("Downloading Thumb File");

                        wc.DownloadFile(strThumbPath, strThumbLocalPath + strThumbfile);

                        wc.Dispose();

                        //new ftp code

                        BytesRoad.Net.Ftp.FtpClient f = new BytesRoad.Net.Ftp.FtpClient();
                        f.PassiveMode = false;

                        f.Connect(999999999, "IPADDRESS OF FTP", 21);
                        f.Login(999999999, "", "");

                        try
                        {
                            f.ChangeDirectory(999999999, objbizet.CLIENTID.ToString().Trim());
                        }
                        catch (Exception e)
                        {
                            f.CreateDirectory(999999999, objbizet.CLIENTID.ToString().Trim());
                            f.ChangeDirectory(999999999, objbizet.CLIENTID.ToString().Trim());
                            Console.WriteLine(e);
                        }

                        f.PutFile(999999999, strVideoFile, "E:\\temp\\" + strVideoFile);



                        Console.WriteLine("Transfer of Video File " + objbizet.Path + " Complete");
                        //response.Close();
                        f.Disconnect(999999999);

                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                        strError = e.ToString();
                    }
                    finally //Update Data
                    {
                        //check if spot Exists ///need to fix

                        //var myquery = from m in db2.Medias
                        //              where m.SpotID == Convert.ToInt32(objbizet.SPOTID.Trim())
                        //              select m;
                        //foreach (var mm in myquery)
                        //{
                        //    //db2.DeleteMedia(objbizet.SPOTID.Trim());
                        //}

                        if (strError == "")
                        {
                            db2.AddMedia(Convert.ToInt32(objbizet.SPOTID), objbizet.Title, objbizet.Keywords, objbizet.Path, strVideoFile, objbizet.CLIENTNAME, Convert.ToInt32(objbizet.CLIENTID), objbizet.SUBCATEGORYNAME, Convert.ToInt32(objbizet.SUBCATEGORYID), Convert.ToDecimal(objbizet.PRICE), strThumbfile, objbizet.Description);
                        }
                        else
                        {
                            db2.AddMedia(Convert.ToInt32(objbizet.SPOTID), "Under Maintenance -  " + objbizet.Title, objbizet.Keywords, objbizet.Path, strVideoFile, objbizet.CLIENTNAME, Convert.ToInt32(objbizet.CLIENTID), objbizet.SUBCATEGORYNAME, Convert.ToInt32(objbizet.SUBCATEGORYID), Convert.ToDecimal(objbizet.PRICE), strThumbfile, objbizet.Description);
                        }
                    }




                }
                //dispose
                db.Dispose();
                db2.Dispose();

            }

    }

}
James Campbell
+1  A: 

1) I am having doubts that the entire file is uploaded to the web server and then it is transferred to WCF Service server...if this is true then i am not getting advantage of streaming as well as iis and web server will be down very soon if user uploads large file or multiple user are uploading files con currently

No, you're confusing stuff here. When you use WCF streaming to upload a large file, the file is being sent in chunks - in blocks of several Kbyte in size. The WCF server - running in IIS or self-hosted in a NT service or a console app - while receive those chunks and write them to disk, as they arrive.

You don't "upload the whole file to the web server" and then "transfer it" to the WCF service - the WCF service itself is receiving and handling the file - and only once.

If you host your WCF service yourself - in a console app, a Winforms app, or a Windows NT Service - there's not even any IIS or web server involved AT ALL. WCF handles it all by itself.

Using WCF streaming is probably one of the most memory efficient and one of the simplest ways to transfer large files to a server.

Check out some more example and blog posts on the topic:

marc_s
Hello mark_s i am also having same idea but can you explain me the scenario which i have explaine in my edit where i am not calling any WCF service still entire file is getting transferred, that is the reason i am feeling that data is first transferred to web server( ASP .Net App Server)
Radhi
@Radhi: I don't understand what exactly you're trying to do...... try to put your WCF service code into an assembly, and write your own self-host - a simple console app will do. Then you're absolutely totally independant of any web server / IIS or anything. Does that work?
marc_s
Actually it is a website to upload the videos and user can share them in between, so i want that user can visit video upload page and able to upload it from that page. So, is it possible to host wcf service in console application and call it from client (as i am not having any control on client machine)is it possible to call WCF service from jquery to upload the file ?Please guide me...
Radhi