Uploading files using WCF

Source: Internet
Author: User
Tags ftp file

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;

  }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.