title: WCF HTTP 204 response
body: <p>I'm consuming a WCF web service from a server I have little control over. Methods not returning any data fire HTTP code 204 which is totally ok in terms of HTTP, however I have a problem with WCF itself handling the response (all other methods returning 400 work just fine).</p>
  
  <p>Here is my method declaration:</p>
  
  <pre><code>  [OperationContract]
    [WebInvoke(UriTemplate = "methodpath/V1",
       RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json,
       BodyStyle = WebMessageBodyStyle.Wrapped)]
    void Operation1(
       [MessageParameter(Name = "username")]
       string userName,
  
       [MessageParameter(Name = "password")]
       string password);
  </code></pre>
  
  <p>Error I get after calling the method:
  CommunicationException: Error in deserializing body of reply message for operation 'Operation1'. The OperationFormatter could not deserialize any information from the Message because the Message is empty (IsEmpty = true).</p>
  
  <p>Also tried with IsOneWay=true:
  InvalidOperationException: The one-way operation returned a non-null message with Action=''.</p>
  
  <p>Here is the raw HTTP response:</p>
  
  <pre><code>HTTP/1.1 204 No Content
  Set-Cookie: ...
  Content-Length: 0
  Connection: Close
  Date: Mon, 21 Mar 2011 18:41:37 GMT
  </code></pre>
  
  <p>exception stack trace:</p>
  
  <p>Server stack trace: </p>
  
  <pre><code>   at System.ServiceModel.Dispatcher.PrimitiveOperationFormatter.DeserializeReply(Message message, Object[] parameters)
     at System.ServiceModel.Dispatcher.DemultiplexingClientMessageFormatter.DeserializeReply(Message message, Object[] parameters)
     at System.ServiceModel.Dispatcher.CompositeClientFormatter.DeserializeReply(Message message, Object[] parameters)
     at System.ServiceModel.Dispatcher.ProxyOperationRuntime.AfterReply(ProxyRpc&amp; rpc)
     at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc&amp; rpc)
     at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
     at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)
     at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
     at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
  </code></pre>
  
  <p>Would be grateful to anyone who has an idea how to force WCF gracefully accept the response.</p>