Uploading files to remote server - c#

I am a WPF newbie and has little experience with C# thread programming. I am assigned a C# WPF application with multi-threading. The requirements for that application is to upload local big files to a
destination folder named "ABC" that sits directly under the root disk driver (e.g. C:\ABC) on a remote server that runs under
Windows platform. I do not know the directions to go. Please advise. Thank you.
Follows are details about the requirements:
Because each uploaded file size is big, there needs a separate thread to run the upload file function.
I plan to use thread programming with async/await and Task object. Any idea?
In WPF I do not know which WPF control to use for upload function. Please help.
For destination folder "ABC", do I need to set its access permission explicitly?
I should use async/await and Task, or BackgroundWorker class?
Update:
WPF application not WCF application. Sorry for my typo.

To transfer large files using WCF service over HTTP, you can use the following types of bindings:
wsHttpBinding
basicHttpBinding
In wsHttpBinding, we can set the TransferMode attribute as Buffered, but there is a disadvantage in using this approach for large files, because it needs to put the entire file in memory before uploading/downloading, A large buffer is required on both the web client and the WCF service host. However, this approach is very useful for transferring small files, securely.
In basicHTTPBinding we can use the TransferMode attribute as Streamed so that the file can be transferred in the form of chunks.
For more information follow this article:
WCF Streaming: Upload/Download Files Over HTTP
and for transfering files over TCP/IP read below articls:
WCF TCP-based File Server
Sending Files using TCP
Large Message Transfer with WCF-Adapters Part 1

Related

WCF Streaming Big file

How can I send the service a ref of a big file on the cliet's computer by a stream object and then start download piece by piece it from the client's computer (I decide how much MB I transfer every sec)? Do I have any limitations when I use it?
IIS doesn't support streaming - it buffers the whole request.
CodeProject article: WCF 4.5 fixes this
Until then, if you use IIS, the whole file will be stored in server memory before it is passed to your service.
The solution for now is to send the file in chunks - each chunk sent in a separate service call.
This would also help with your bandwidth throttling. This is not built into WCF - you have to do it yourself. You can throttle each chunk either on the client or on the server.

Concurrency management in WCF

i have implemented a fairly simple wcf service which handles the file transfers from my clients to the server the problem is when a client sends a file request.
all of the bandwidth is allocated to that single client and others have to wait until the requested file transfer is completed.
So my question is how to make the service more efficient and let the users share the bandwidth
[ServiceBehavior(IncludeExceptionDetailInFaults = true, InstanceContextMode =InstanceContextMode.PerCall,
ConcurrencyMode=ConcurrencyMode.Multiple)]
I set the InstanceContextMode attribute to PerCall but that didn't do the trick
UPDATE : This Project is similar to mine
http://www.codeproject.com/Articles/33825/WCF-TCP-based-File-Server
WCF does not have proper load balancing, you will have to develop one yourself.
If you are transferring files, lets assume download, you should send packets of data rather than the complete file at once. When doing this, add 'delays/sleeps' to the process to limit the amount of bytes the server sends on each time window, this will make room for other requests.
It's questionable that it's desirable to serve up files through a WCF endpoint. The reasons against doing this are pretty much exactly the problems you have been having. It works for a few clients at a time - but scaling out requires hosting new instances of the service behind a load balancer.
It would be worth considering hosting your files with some kind of storage service and have your WCF service simply return a link or handle to the file. Then the file can be retrieved offline. Microsoft have created Azure Blob Storage for this exact purpose.
Appreciate this does not address your original question, and understand the scope of your requirement may not accommodate a large reworking.
Another option is to use chunking channel if you are transferring large files. Examples: MSDN, codeplex.
Although I agree with #hugh position.

WCF Webservice and Silverlight with compression

My application consists of a WCF web service and a silverlight client. I need to transfer data on the order of GBs. Is it possible to send compressed data so that it can be uncompressed by the client when it is received? What classes can I make use for this?
I never had to use it but maybe you should take a look at SharpZipLib (An open source dll for compression)
Here's also 3 links about WCF compression:
http://bloggingabout.net/blogs/ramon/archive/2008/11/06/wcf-and-http-gzip-deflate-compression-and-silverlight.aspx
http://weblogs.asp.net/cibrax/archive/2006/03/29/441398.aspx
http://frenk.wordpress.com/2009/11/08/gzip-compression-between-wcf-web-service-and-silverlight/

Available options for hosting FTP server in .NET application

I need to implement an FTP service inside my .NET application (running as a Windows Service) and have not had much luck finding good/current source code or vendors. Ideally it needs to be able to respond to the basic FTP Protocol and accept the data stream from an upload via a stream, enabling me to process the data as it is being received (think on the fly hashing).
I need to be able to integrate it into my service because it will stack on top of our current code base with an existing custom TCP/IP communication protocol. I don't want to write (and then spend time debugging and performance testing) my own protocol, or implementation.
I have already found plenty of ftp client implementations, I just need an acceptable server solution.
There is an article about rolling your own FTP server in C# here. It's a bit old, but it might be complete enough for your requirements.
If you can get away from the need to process inbound data on-the-fly, I'd suggest just using an off-the-shelf FTP server (maybe even IIS), and process the received files from a folder. Your service could easily monitor this folder for new files. The other benefit of this is that files could be received even if your service is not running or restarting, and testing would be easier as you can drop your own files into the monitored folder.
Good luck!
Hope you find RemObjects free IP nice to use,
http://www.remobjects.com/ip.aspx
After installation you will see the samples.

WCF communication with several clients without IIS

we're working on a peer to peer comm software that would allow a number of grocery stores to sync their inventory with what we call "headquarters".
To so this, we're thinking WCF+WPF, and no IIS and web services. My experience with WCF is basically zero, so my question is whether a TCP comm solution using WCF would work. The data that's being transferred is quite limited, about 2MB for a compressed plain text file (so we're sending binary data!), and this is done once per day only. So bandwidth/load shouldn't be an issue here.
The idea at this point is to have a WCF "server" running at HQ. Stores make themselves known to that server and then send files back and forth (simliliar to a chat application).
What I'm not sure of: does every store need to have a WCF "server" (or endpoint)? How would the server (=HQ) send a file to one of the clients (=stores)? Every store can send a file to any other store, and the HQ, and every store can also "request" a file from any other store/HQ.
Two limitations: None of the machines/computers involved can run Windows server for budget reasons, and as stated before IIS is a no-go.
If you are only sending files back and forth, I might question whether or not WCF even makes any sense. Have you considered just using a file transfer protocol, like scp or sftp?
Every machine will have to accept connections and have a file drop location setup, and then yuor application will have to monitor that location for new files. I love WCF in general, but a file transfer protocol is going to have a leg up if that is all you want to do.
If you direct all of your traffic via the server then there's no reason why you couldn't achieve this with WCF. The server would host WCF services in IIS with the stores having a client that was able to upload and request files. With this method, stores would not be able to directly transfer fiels to each other, but they would have to do it via the main server, which would suit your needs if you don't have the budget for the other scenario.
If all transfers are made once per day, the requests for files would be made with each client requesting what files they require, followed by each client uploading any files that are required by the server or any other client. The final step would be the server distributing the required files to each client. Obviously, this is a simplified view of it, the actual process may require some more thinking.
You don't need to host WCF in IIS, but is there any particular reason you don't want to do that?
You can host WCF in a ServiceHost, but then you need to build, maintain and deploy a lot of server/service features that IIS provides for free, such as application process recycling, activation-based hosting, etc.
In any case, it almost sounds like you need peer to peer networking. You can do that with WCF using the NetPeerTcpBinding.
If you have an opportunity to redesign your application, I suggest you do. You can throw strings around in WCF but if you can create a data contract you can keep all your communication strongly typed.
If you have access to windows server 2008 then the new IIS can host your WCF even if it isn't using tcp. Otherwise you just need to write an application that opens a service host, which you would usually wrap into a windows service. But as #MArk Seemann pointed out, you get lots of freebies by running your service in IIS.
Don't have any experience with the PeerTcpBinding but I can tell you that the NetTcpBinding is nice and fast plus it comes with all sorts of goodies like encryption and authentication if you want it.

Categories

Resources