WCF did not appear before, I have been using WebService to upload files, I do not know why others do so, because our file server and Web site backstage and the front desk are not the same machine, operators feel the use of FTP file is too cumbersome to send files, I will do a dedicated upload file WebService, the webservice deployed in the file server, and then in the background of the site call this webservice, the site back page upload file into the byte circulated to WebService, Then webservice the stream to save the file to a Web site that only allows static pages (static sites can prevent some script Trojans).
WebService to upload files The problem is inefficient, and can not transfer large amounts of data files, of course, you can use the Mtom in WSE to transfer large files, with WCF is much better, by using WCF pass stream object to pass large data files, but there are some limitations:
1. Only BasicHttpBinding, nettcpbinding and netnamedpipebinding support the transfer flow data.
2, the stream data type must be serializable stream or MemoryStream.
3. The message body cannot contain other data when passed.
4, Transfermode restrictions and maxreceivedmessagesize restrictions.
The following concrete implementation: Create a new Wcfservice, the interface file code as follows:
[ServiceContract]
public interface IUpLoadService
{
[OperationContract(Action = "UploadFile", IsOneWay = true)]
void UploadFile(FileUploadMessage request);
}
[MessageContract]
public class FileUploadMessage
{
[MessageHeader(MustUnderstand = true)]
public string SavePath;
[MessageHeader(MustUnderstand = true)]
public string FileName;
[MessageBodyMember(Order = 1)]
public Stream FileData;
}