title: Consume C# REST service with Java client
body: <p>I have following C# REST service definition</p>
  
  <pre><code>[OperationContract]
  [WebInvoke(Method = "POST", UriTemplate = "books/{isbn}")]
  void CreateBook(string isbn, Book book);
  </code></pre>
  
  <p>I want to consume this service from a Java client.</p>
  
  <pre><code>    String detail = "&lt;Book&gt;&lt;Autor&gt;" + autor + "&lt;/Autor&gt;&lt;ISBN&gt;" + isbn + "&lt;/ISBN&gt;&lt;Jahr&gt;" + jahr + "&lt;/Jahr&gt;&lt;Titel&gt;" + titel + "&lt;/Titel&gt;&lt;/Book&gt;";
      URL urlP = new URL("http://localhost:18015/BookRestService.svc/books/" + isbn);
      HttpURLConnection connectionP = (HttpURLConnection) urlP.openConnection();
      connectionP.setReadTimeout(15*1000);
      connectionP.setConnectTimeout(15*1000);
      connectionP.setRequestMethod("POST");
      connectionP.setDoOutput(true);
      connectionP.setRequestProperty("Content-Type", "application/xml"); 
      connectionP.setRequestProperty("Content-Length", Integer.toString( detail.length() )); 
      OutputStream os = connectionP.getOutputStream();
      PrintWriter pw = new PrintWriter(new OutputStreamWriter(os));
      pw.println(detail);
      pw.flush();
      pw.close();
      int retc = connectionP.getResponseCode();
      connectionP.disconnect();
  </code></pre>
  
  <p>The service returns 400 to my Java client. The same service works fine when called from a C# client.</p>