title: Sending a SOAP XML manually and receiving a HTTP 500 error code and binary data in the response
body: <p>I am using ruby to send a SOAP request to a very enterprisey bla bla service, so unfortunately I can not attach any samples, there's nobody to send any server-side logs, nobody knows whats wrong on the provider side or how the actual HTTP requests need to look like (except a single XML example I got, but no HTTP headers), the docs are very Microsoft-centric with C# examples and whatnot ("instantiate AbstractFactoryFactory..." and whatnot), long live enterprise software.</p>
  
  <p>But the bottom line is, eventually I took one of their own XMLs from their logs and sent it via HTTP to the endpoint from the WSDL and sent it to their host using the <a href="http://savonrb.com/version2/locals.html" rel="nofollow">Savon gem raw XML option</a> and got a HTTP 500 error from their host and a bunch of non-ascii binary data inside - literally, no ASCII characters are in the body.</p>
  
  <p>I guessed that maybe Savon does some bad magic or that the XML option is not working as expected and I tried sending the same request via Faraday, but got the same thing,</p>
  
  <p>the HTTP response headers says it's a HTTP response, XML encoded, from an ASP.NET host:</p>
  
  <pre><code> "content-type"=&gt;"text/xml; charset=utf-8",
   "server"=&gt;"Microsoft-IIS/7.5",
   "x-aspnet-version"=&gt;"2.0.50727",
   "x-powered-by"=&gt;"ASP.NET",
  </code></pre>
  
  <p>but again, a 440 bytes worth of binaries in the response:</p>
  
  <pre><code>method=:post,
  body=
    "\x1F\x8B\b\x00\x00...
  </code></pre>
  
  <p>etc.</p>
  
  <p>Am I missing some weird aspect of the SOAP specification and I need to do something to decode this data or has their server gone bonkers from my XML, HTTP headers or something else and I need to ping the provider?</p>
  
  <h1>Update 1</h1>
  
  <p>I noticed that their original XML had UTF-16 encoding set, so I tried encoding the raw string to UTF-16, then had Savon spew errors at me about bad data, then I updated encoding in the Savon client config. But I still get HTTP 500 error and binaries as response and if I try to log anything Savon reports a bug:</p>
  
  <pre><code>Encoding::CompatibilityError: incompatible encoding regexp match (US-ASCII regexp with UTF-16 string)
  from /home/bbozo/.rvm/gems/ruby-2.2.4/gems/savon-2.11.1/lib/savon/log_message.rb:13:in `to_s'
  </code></pre>
  
  <p>Faraday basically reported the same behavior, an binary blob.</p>
  
  <h1>Update 2</h1>
  
  <p>I tried piping the encoding to every known encoding, and got nothing, even though the HTTP headers imply the encoding is UTF-8, it obviously isn't</p>
  
  <pre><code>Encoding.name_list.map{ |e_in| [ e_in, ( response.body.dup.force_encoding(e_in).encode('utf-8') rescue 'incompatible' ) ] }
  </code></pre>
  
  <p>There is nothing that would indicate the encoding in the WSDL files, the API spec doesn't even mention encoding except that the request XMLs need to be UTF-8 encoding, I tried encoding the body, changing the XML encoding definition, HTTP headers, but still I get the same binary blob, with the same heading (<code>\x1F\x8B\b\x00\x00</code>) - so it's not some weird encryption either.</p>
  
  <p>Compression maybe?</p>
  
  <p>I tried with https for good measure and nothing.</p>
  
  <h1>Question</h1>
  
  <p>Am I missing some weird aspect of the SOAP specification and I need to do something to decode this data or has their server gone bonkers from my XML, HTTP headers or something else and I need to ping the provider?</p>