title: RESTful WCF Service returns a 400 code when sending "raw" XML
body: <p>I have been banging my head of the wall for two days with this so, hopefully, someone can give me a hand.  What I have is a RESTful Web Service that I wrote using WCF; nothing to it really just two methods that accept a single string parameter and also return a string. Both the parameter and return value are straight XML.</p>
  
  <pre><code>[ServiceContract]
  public interface IService
  {
      [OperationContract]
      [WebGet(UriTemplate = "/method1/{data}", BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Xml, RequestFormat = WebMessageFormat.Xml)]
      string Method1(string data);
  
      [OperationContract]
      [WebGet(UriTemplate = "/method2/{data}", BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Xml, RequestFormat = WebMessageFormat.Xml)]
      string Method2(string data);
  
  }
  </code></pre>
  
  <p>For the sake of argument lets say that the implementation of both of these methods looks like this:</p>
  
  <pre><code>public string Method1(string data)
  {
      return string.Format("You entered: {0}", data);
  }
  </code></pre>
  
  <p>If I goto http: //myuri.com/service.svc/method1/foo the following is wrote to the browser:</p>
  
  <pre><code>  &lt;string xmlns="http://schemas.microsoft.com/2003/10/Serialization/"&gt;You 
      entered: foo&lt;/string&gt; 
  </code></pre>
  
  <p>This works great but if I change the url to: http: //myuri.com/service.svc/method1/&lt;foo &gt; I get a 400 (Bad Request).  So I enabled some tracers to see what was going using the following code:</p>
  
  <pre><code>&lt;system.diagnostics&gt;
  &lt;sources&gt;
    &lt;source name="System.ServiceModel"
            switchValue="All"&gt;
      &lt;listeners&gt;
        &lt;add name="traceListener"
            type="System.Diagnostics.XmlWriterTraceListener"
            initializeData= "c:\Traces.svclog" /&gt;
      &lt;/listeners&gt;
    &lt;/source&gt;
  &lt;/sources&gt;
  </code></pre>
  
  <p></p>
  
  <p>As you can see I am using the switch value 'All' to capture every event that happens during the execution of this service.  I ran back through a few times using the URL format that works to verify that the tracers were working and they were.  I then went to the URL that contained the XML tag foo and recieved the 400 error as expected but when I went back to the log file there had been no additional information appened to the end of it.  This leads me to believe that the 400 error is being displayed before the WCF service is ever invoked. </p>
  
  <p>Lastly, I switched the the methods from 'GET' methods to 'POST' methods, wrote a bit of code using WebRequest / WebResponse with the same result.  Now I have read some posts talking about using the XmlSerializer on the client side to send the data to the service but that defeats the purpose of this service.  While I am using .NET to write the service it is likely that PHP or classic ASP scripts will be connecting to this service and they, obviously, do not have access to the XmlSerializer. </p>
  
  <p>So my million dollar question is this:  Is it possible to send a 'raw' XML request to a RESTful webservice developed in WCF and, if so, how?</p>
  
  <p>P.S.
  The XML coming into and going out of the service is not based on any tangible object it is simply the structure I created to use with this service. The XML coming in is parsed via XPath, the values are placed into a larger XML string, and passed along to an external API.  The results from that API are processed and then returned by my RESTful service.</p>
  
  <p>Any help would be greatly appreciated!!</p>