title: REST Web Service 400 error when calling function
body: <p>I have made a REST Web service, that works with Visual Studios WCF Test Client. 
  Can call it with a website that sits next to it and uses a "proxy" class that was created with svcutil.</p>
  
  <p>I can also see the service is there when I Browse to the .svc file. (http://localhost/service1.svc) It comes up with the "You have created a service." webpage.</p>
  
  <p>HOWEVER</p>
  
  <p>When i try and call a function within the service, (http://localhost/service.svc/firstName/lastName) it returns a 400 error code. </p>
  
  <p>I recently had seperate error that I couldn't figure out so I found a tutorial on a VERY basic web service " <a href="http://blog.weareon.net/how-to-create-and-consume-rest-web-service-using-wcf/" rel="nofollow">http://blog.weareon.net/how-to-create-and-consume-rest-web-service-using-wcf/</a> ", that one stopped the previous error, but still has the 400 error when trying to call a function.</p>
  
  <p>My .config file was cut back to the bare bones to try to get it work before i get in too far.</p>
  
  <pre><code>    &lt;?xml version="1.0"?&gt;
  &lt;configuration&gt;
  
    &lt;system.web&gt;
      &lt;compilation debug="true" targetFramework="4.0" /&gt;
    &lt;/system.web&gt;
    &lt;system.serviceModel&gt;
      &lt;services&gt;
        &lt;service name="VService"&gt;
          &lt;endpoint address="" binding="webHttpBinding" contract="ServiceName.IService1" behaviorConfiguration="webBehavior" /&gt;
        &lt;/service&gt;
      &lt;/services&gt;
      &lt;behaviors&gt;
        &lt;endpointBehaviors&gt;
          &lt;behavior name="webBehavior"&gt;
            &lt;webHttp/&gt;
          &lt;/behavior&gt;
        &lt;/endpointBehaviors&gt;
  
        &lt;serviceBehaviors&gt;        
          &lt;behavior&gt;
            &lt;!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment --&gt;
            &lt;serviceMetadata httpGetEnabled="true"/&gt;
            &lt;!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information --&gt;
            &lt;serviceDebug includeExceptionDetailInFaults="true"/&gt;
          &lt;/behavior&gt;
        &lt;/serviceBehaviors&gt;
      &lt;/behaviors&gt;
      &lt;serviceHostingEnvironment multipleSiteBindingsEnabled="true" /&gt;
    &lt;/system.serviceModel&gt;
   &lt;system.webServer&gt;
      &lt;modules runAllManagedModulesForAllRequests="true"/&gt;
    &lt;/system.webServer&gt;
  
    &lt;system.diagnostics&gt;
      &lt;trace autoflush="true"  /&gt;
      &lt;sources&gt;
        &lt;source name="System.ServiceModel"
                switchValue="Information, Error"
                propagateActivity="true"&gt;
          &lt;listeners&gt;
            &lt;add name="sdt"
                type="System.Diagnostics.XmlWriterTraceListener"
                initializeData= "SdrConfigExample1.e2e" /&gt;
          &lt;/listeners&gt;
        &lt;/source&gt;
      &lt;/sources&gt;
    &lt;/system.diagnostics&gt;
  
  &lt;/configuration&gt;
  </code></pre>
  
  <p>In my research, I have found things like, proxy settings in the browser, return types, size issues, but none have worked so far.</p>
  
  <p>If you have any ideas, please let me know.
  Thanks in advance.</p>
  
  <p>EDIT:</p>
  
  <p>this is the XML from the log file, thanks for the comments to let me know this exists :)</p>
  
  <pre><code>&lt;E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent"&gt;
  &lt;System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system"&gt;
  &lt;EventID&gt;131075&lt;/EventID&gt;
  &lt;Type&gt;3&lt;/Type&gt;
  &lt;SubType Name="Error"&gt;0&lt;/SubType&gt;
  &lt;Level&gt;2&lt;/Level&gt;
  &lt;TimeCreated SystemTime="2012-02-15T03:24:00.9952760Z" /&gt;
  &lt;Source Name="System.ServiceModel" /&gt;
  &lt;Correlation ActivityID="{00000000-0000-0000-0000-000000000000}" /&gt;
  &lt;Execution ProcessName="WebDev.WebServer40" ProcessID="3128" ThreadID="4" /&gt;
  &lt;Channel /&gt;
  &lt;Computer&gt;ACKZ-01&lt;/Computer&gt;
  &lt;/System&gt;
  &lt;ApplicationData&gt;
  &lt;TraceData&gt;
  &lt;DataItem&gt;
  &lt;TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Error"&gt;
  &lt;TraceIdentifier&gt;http://msdn.microsoft.com/en-US/library/System.ServiceModel.Diagnostics.ThrowingException.aspx&lt;/TraceIdentifier&gt;
  &lt;Description&gt;Throwing an exception.&lt;/Description&gt;
  &lt;AppDomain&gt;9b0666f2-9-129737498327838293&lt;/AppDomain&gt;
  &lt;Exception&gt;
  &lt;ExceptionType&gt;System.ServiceModel.ProtocolException, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089&lt;/ExceptionType&gt;
  &lt;Message&gt;There is a problem with the XML that was received from the network. See inner exception for more details.&lt;/Message&gt;
  &lt;StackTrace&gt;
  at System.ServiceModel.Channels.HttpRequestContext.CreateMessage()
  at System.ServiceModel.Channels.HttpChannelListener.HttpContextReceived(HttpRequestContext context, Action callback)
  at System.ServiceModel.Activation.HostedHttpTransportManager.HttpContextReceived(HostedHttpRequestAsyncResult result)
  at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.HandleRequest()
  at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.BeginRequest()
  at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.OnBeginRequest(Object state)
  at System.Runtime.IOThreadScheduler.ScheduledOverlapped.IOCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
  at System.Runtime.Fx.IOCompletionThunk.UnhandledExceptionFrame(UInt32 error, UInt32 bytesRead, NativeOverlapped* nativeOverlapped)
  at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)
  &lt;/StackTrace&gt;
  &lt;ExceptionString&gt;System.ServiceModel.ProtocolException: There is a problem with the XML that was received from the network. See inner exception for more details. ---&amp;gt; System.Xml.XmlException: The body of the message cannot be read because it is empty.
     --- End of inner exception stack trace ---&lt;/ExceptionString&gt;
  &lt;InnerException&gt;
  &lt;ExceptionType&gt;System.Xml.XmlException, System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089&lt;/ExceptionType&gt;
  &lt;Message&gt;The body of the message cannot be read because it is empty.&lt;/Message&gt;
  &lt;StackTrace&gt;
  at System.ServiceModel.Channels.HttpRequestContext.CreateMessage()
  at System.ServiceModel.Channels.HttpChannelListener.HttpContextReceived(HttpRequestContext context, Action callback)
  at System.ServiceModel.Activation.HostedHttpTransportManager.HttpContextReceived(HostedHttpRequestAsyncResult result)
  at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.HandleRequest()
  at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.BeginRequest()
  at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.OnBeginRequest(Object state)
  at System.Runtime.IOThreadScheduler.ScheduledOverlapped.IOCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
  at System.Runtime.Fx.IOCompletionThunk.UnhandledExceptionFrame(UInt32 error, UInt32 bytesRead, NativeOverlapped* nativeOverlapped)
  at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)
  &lt;/StackTrace&gt;
  &lt;ExceptionString&gt;System.Xml.XmlException: The body of the message cannot be read because it is empty.&lt;/ExceptionString&gt;
  &lt;/InnerException&gt;
  &lt;/Exception&gt;
  &lt;/TraceRecord&gt;
  &lt;/DataItem&gt;
  &lt;/TraceData&gt;
  &lt;/ApplicationData&gt;
  &lt;/E2ETraceEvent&gt;
  </code></pre>
  
  <p>Haven't completely studied it yet, thought I would post it at the same time </p>
  
  <p>EDIT 2</p>
  
  <p>CODE FROM THE SERVICE</p>
  
  <pre><code>namespace VeryBasicService
  {
      // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
      [ServiceContract]
      public interface IService1
      {
  
          [OperationContract]
          string GetData(int value);
  
          [OperationContract]
          CompositeType GetDataUsingDataContract(CompositeType composite);
  
          [OperationContract]
          [WebGet(UriTemplate="/{firstname}/{lastname}")]
          string CallRestService(string firstName, string lastName);      
  
  
          // TODO: Add your service operations here
      }
  </code></pre>
  
  <p>CODE OF THE FUNCTION</p>
  
  <pre><code>namespace VeryBasicService
  {
      // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
      public class Service1 : IService1
      {
          public string GetData(int value)
          {
              return string.Format("You entered: {0}", value);
          }
  
          public CompositeType GetDataUsingDataContract(CompositeType composite)
          {
              if (composite == null)
              {
                  throw new ArgumentNullException("composite");
              }
              if (composite.BoolValue)
              {
                  composite.StringValue += "Suffix";
              }
              return composite;
          }
          public string CallRestService(string firstName, string lastName)
          {
              return firstName + " " + lastName;            
          }      
      }
  }
  </code></pre>