title: body parameter 'width'. GET operations cannot have a body?
body: <p>Im trying to get an image from a wcf rest service like so:</p>
  
  <pre><code>[ServiceContract]
  public interface IReceiveData
  {
      [OperationContract]
      [WebInvoke(Method = "GET", BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Xml, UriTemplate = "picture/")]
      //this line is wrong though
      Stream GetImage(int width, int height);
  }
  public class RawDataService : IReceiveData
  {
      public Stream GetImage(int width, int height)
      {
          // Although this method returns a jpeg, it can be
          // modified to return any data you want within the stream
          Bitmap bitmap = new Bitmap(width, height);
          for (int i = 0; i &lt; bitmap.Width; i++)
          {
              for (int j = 0; j &lt; bitmap.Height; j++)
              {
                  bitmap.SetPixel(i, j, (Math.Abs(i - j) &lt; 2) ? Color.Blue : Color.Yellow);
              }
          }
          MemoryStream ms = new MemoryStream();
          bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
          ms.Position = 0;
          WebOperationContext.Current.OutgoingResponse.ContentType = "image/jpeg";
          return ms;
      }
  }
  </code></pre>
  
  <p>In my host application:</p>
  
  <pre><code>class Program
      {
          static void Main(string[] args)
          {
              string baseAddress = "http://" + Environment.MachineName + ":8000/Service";
              ServiceHost host = new ServiceHost(typeof(RawDataService), new Uri(baseAddress));
              host.AddServiceEndpoint(typeof(IReceiveData), new WebHttpBinding(), "").Behaviors.Add(new WebHttpBehavior());
              host.Open(); // this line
              Console.WriteLine("Host opened");
              Console.ReadLine();
  </code></pre>
  
  <p>I get this error:</p>
  
  <blockquote>
    <p>Operation 'GetImage' in contract 'IReceiveData' uses GET, but also has
    body parameter 'width'. GET operations cannot have a body. Either make
    the parameter 'width' a UriTemplate parameter, or switch from
    WebGetAttribute to WebInvokeAttribute.</p>
  </blockquote>
  
  <p>Im not sure how you set the webinvoke/UriTemplate method for an image or how you get an image and return it. Can some one post the correct way to display an image in this example. </p>
  
  <p><strong>EDIT</strong></p>
  
  <p>If I try the below answer and use <code>UriTemplate = "picture?w={width}&amp;h={height}"</code> as my UriTemplate when navigating to <code>http://www.localhost.com:8000/Service/picture?width=50&amp;height=40</code> I recieve an error in my code:</p>
  
  <pre><code>public Stream GetImage(int width, int height)
          {
              Bitmap bitmap = new Bitmap(width, height); // this line
              for (int i = 0; i &lt; bitmap.Width; i++)
              {
                  for (int j = 0; j &lt; bitmap.Height; j++)
                  {
                      bitmap.SetPixel(i, j, (Math.Abs(i - j) &lt; 2) ? Color.Blue : Color.Yellow);
                  }
              }
              MemoryStream ms = new MemoryStream();
              bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
              ms.Position = 0;
              WebOperationContext.Current.OutgoingResponse.ContentType = "image/jpeg";
              return ms;
          }
  </code></pre>
  
  <p>Which states <code>ArguementException was unhandled by user code:</code><strong>Parameter is not valid.</strong></p>