title: Simple WCF POST with Uri Template
body: <p>I thought this would be incredibly simple, but I must be missing something. I am trying to make a simple WCF POST request in conjunction with a UriTemplate. I have read numerous examples where people use a stream paramater as the last paramater, and this is supposed to pick up the POST body. I can only get this to work if the stream is the only paramater.</p>
  
  <p>I've gone back to basics with a simple Hello World service.</p>
  
  <p>Here is my code on the client </p>
  
  <pre><code>static string Test()
  {
      HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create("http://localhost:1884/MyAPI/Service.svc/HelloWorld");
      req.Method = "POST";
      req.ContentType = "text/plain";
      Stream reqStream = req.GetRequestStream();
      byte[] fileToSend = System.Text.UTF8Encoding.UTF8.GetBytes("sometext");
      reqStream.Write(fileToSend, 0, fileToSend.Length);
      reqStream.Close();
      HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
      var sr = new StreamReader(resp.GetResponseStream());
      return sr.ReadToEnd();
  }
  </code></pre>
  
  <p>And this is the code on the service</p>
  
  <pre><code>[ServiceContract]
  public interface IService
  {
      [OperationContract]
      [WebInvoke(Method = "POST", UriTemplate = "HelloWorld")]
      Stream HelloWorld(Stream content);
  }
  
  public Stream HelloWorld(Stream content)
  {
      var sr = new StreamReader(content);
      string text = sr.ReadToEnd();
      return new System.IO.MemoryStream(Encoding.UTF8.GetBytes("Hello World! " + text)); 
  }
  </code></pre>
  
  <p>This all works fine. Then I make this change:</p>
  
  <pre><code>[ServiceContract]
  public interface IService
  {
      [OperationContract]
      [WebInvoke(Method = "POST", UriTemplate = "HelloWorld/test/{test}")]
      Stream HelloWorld(string test, Stream content);
  }
  
  public Stream HelloWorld(string test, Stream content)
  {
      var sr = new StreamReader(content);
      string text = sr.ReadToEnd();
      return new System.IO.MemoryStream(Encoding.UTF8.GetBytes("Hello World! " + text + test)); 
  }
  </code></pre>
  
  <p>And change the client code to hit HelloWorld/test/sometext</p>
  
  <p>I get a 500 Internal Server Error. I've tried about 10 different variations including using a ?key=value type UriTemplate, returning strings instead of streams etc, and no luck.</p>
  
  <p>Feels like I'm missing some tiny little thing that is going to make this work, as I have seen countless examples of exactly this all over the web. Theirs works, mine doesn't.</p>
  
  <p>Any ideas?</p>