title: Passing XML string in the body of WCF REST service using WebInvoke
body: <p>I'm a newbie to WCF, REST etc. I'm trying to write a service and a client. 
  I want to pass xml as string  to the service and get some response back.</p>
  
  <p>I am trying to pass the xml in the body to the POST method, but when I run my client, it just hangs.</p>
  
  <p>It works fine when I change the service to accept the parameter as a part of the uri.
  (when I change UriTemplate from "getString" to "getString/{xmlString}" and pass a string parameter).</p>
  
  <p>I'm pasting the code below.</p>
  
  <h1>Service</h1>
  
  <pre><code>[ServiceContract]
  public interface IXMLService
  {
      [WebInvoke(Method = "POST", UriTemplate = "getString", BodyStyle=WebMessageBodyStyle.WrappedRequest, 
      RequestFormat = WebMessageFormat.Xml, ResponseFormat = WebMessageFormat.Xml)]
  
      [OperationContract]
      string GetXml(string xmlstring);
  }
  </code></pre>
  
  <p>// Implementaion Code</p>
  
  <pre><code>public class XMLService : IXMLService
  {
      public string GetXml(string xmlstring)
      {
          return "got 1";
      } 
  }    
  </code></pre>
  
  <h1>Client</h1>
  
  <pre><code>string xmlDoc1="&lt;Name&gt;";        
  xmlDoc1 = "&lt;FirstName&gt;First&lt;/FirstName&gt;";
  xmlDoc1 += "&lt;LastName&gt;Last&lt;/LastName&gt;";
  xmlDoc1 += "&lt;/Name&gt;";
  
  HttpWebRequest request1 = (HttpWebRequest)WebRequest.Create(@"http://localhost:3518/XMLService/XMLService.svc/getstring");
  request1.Method = "POST";
  request1.ContentType = "application/xml";
  byte[] bytes = Encoding.UTF8.GetBytes(xmlDoc1);        
  request1.GetRequestStream().Write(bytes, 0, bytes.Length); 
  
  Stream resp = ((HttpWebResponse)request1.GetResponse()).GetResponseStream();
  StreamReader rdr = new StreamReader(resp);
  string response = rdr.ReadToEnd();
  </code></pre>
  
  <p>Could somebody please point out what's wrong in it?</p>