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 |