Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The answer stems from what I have done before. The service may look as follows:</p> <pre><code>[ServiceContract] public class DocumentService { [OperationContract] [WebTemplate("{name}"] public Document Create(Stream stream, string name) { var id = Guid.NewGuid().ToString("N"); using(FileStream outputStream = File.Create(Path.Combine("c:\\temp\\", id))) { stream.CopyTo(outputStream); } Document document = new Document(); document.Name = name; document.Id = id; // Save document to database // Set headers return document; } } </code></pre> <p>where Document may look as follows:</p> <pre><code>[DataContract] public class Document { [DataMember] public string Id { get;set; } [DataMember] public string Name { get;set; } /* other fields */ } </code></pre> <p>To upload a file to the service (assuming it is at <a href="http://api.example.com/documents/" rel="nofollow">http://api.example.com/documents/</a>), you can do the following:</p> <pre><code>string name = "mydocument.doc"; var request = WebRequest.Create ("http://api.example.com/documents/" + name); request.ContentType = "application/octet-stream"; request.Method = "POST"; using(var stream = request.GetRequestStream()) { using(var inputStream = File.OpenRead("c:\\mydocument.doc")) { inputStream.CopyTo(stream); } } using(var response = (HttpWebResponse)request.GetResponse()) { // process the response, if needed } </code></pre> <p>There is no need to send a multipart stream over if all you do is sending one stream. It is important that any parameters (such as name) should be part of the UriTemplate.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload