Call WCF for upload and download in restful way

Source: Internet
Author: User

In the previous articles, how WCF interacts with Ajax, how to return JSON data to Ajax, how to provide data for ExtJS controls, how to asynchronously invoke restful WCF services with HTTP access, This article focuses on how to use the restful way to invoke WCFL file upload and download. In the previous article, restful WCF supported the two-format data format for requests and responses: 1 XML 2 JSON. In fact, WCF not only supports both of these formats, it also supports native data (raw, from Carlos ' blog). As a result, WCF's restful approach actually supports any format, since the native means that it can be any format, and WCF maintains the original data format of the data from the client to the server, from the server to the client. By looking at the description of the WebMessageEncodingBindingElement class in MSDN: This argument can also be found

First, summarize how to pass raw data (raw) on the server side and client of restful WCF, in WCF, When returning a value or a derived type with a parameter of System.IO.Stream or System.IO.Stream, it is possible to transmit the native data by adding the HTTP request and the contenttype of the RESTful service operation response message.

The following is an example of a project that uploads and downloads a picture file to illustrate the above conclusion.

Step one: In VS2008, create a solution: Wcfbinaryrestful, including four items: as shown in the following illustration:

The descriptions of each of these items are described in the following table:

Project name Description
Wcfbinaryrestful.contracts Contract part of WCF service
Wcfbinaryrestful.service WCF Service Specific Implementation section
Wcfbinaryrestful.host Hosting program for the console program for WCF services
Wcfbinaryrestful.client Client

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.