diff --git a/src/Tests/XmlRpcMessagesTest.php b/src/Tests/XmlRpcMessagesTest.php
index c0b3122..7e9fbf9 100644
--- a/src/Tests/XmlRpcMessagesTest.php
+++ b/src/Tests/XmlRpcMessagesTest.php
@@ -7,7 +7,8 @@
 
 namespace Drupal\xmlrpc\Tests;
 
-use Drupal\simpletest\WebTestBase;
+use Drupal\xmlrpc\XmlRpcTrait;
+use GuzzleHttp\Exception\RequestException;
 
 /**
  * Tests large messages and method alterations.
@@ -16,6 +17,8 @@ use Drupal\simpletest\WebTestBase;
  */
 class XmlRpcMessagesTest extends XmlRpcTestBase {
 
+  use XmlRpcTrait;
+
   /**
    * Modules to enable.
    *
@@ -55,4 +58,57 @@ class XmlRpcMessagesTest extends XmlRpcTestBase {
     $this->assertEqual($removed, 'system.methodSignature', 'Hiding builting system.methodSignature with hook_xmlrpc_alter works');
   }
 
+  /**
+   * Ensure that XML-RPC client sets correct encoding in request http headers.
+   */
+  public function testRequestContentTypeDefinition() {
+    $headers = xmlrpc($this->getEndpoint(), array('test.headerEcho' => array()));
+    $this->assertIdentical($headers['Content-Type'], 'text/xml; charset=utf-8');
+  }
+
+  /**
+   * Check XML-RPC client and server encoding information.
+   *
+   * Ensure that XML-RPC client sets correct processing instructions for XML
+   * documents.
+   *
+   * Ensure that XML-RPC server sets correct encoding in response http headers
+   * and processing instructions for XML documents.
+   */
+  public function testRequestAndResponseEncodingDefinitions() {
+    $url = $this->getEndpoint();
+    $client = \Drupal::httpClient();
+
+    // We can't use the xmlrpc() function here, because we have to access the
+    // full Guzzle response.
+    module_load_include('inc', 'xmlrpc');
+    $xmlrpc_request = xmlrpc_request('system.listMethods', array());
+
+    $headers = ['Content-Type' => 'text/xml; charset=utf-8'];
+    $options = [
+      'headers' => $headers,
+      'body' => $xmlrpc_request->xml,
+    ];
+    $request = $client->createRequest('POST', $url, $options);
+    try {
+      $response = $client->send($request);
+      $data = $response->getBody();
+      $content_type = $response->getHeader('Content-Type');
+    }
+    catch (RequestException $e) {
+      $this->fail($e->getMessage(), '"Normal" exception');
+    }
+    catch (\Exception $e) {
+      $this->fail($e->getMessage(), 'Unexpected exception');
+    }
+
+    // The request string contains some header data before
+    // the xml itself starts with the processing instruction.
+    $this->assertIdentical(0, strpos($request->getBody(), '<?xml version="1.0" encoding="utf-8" ?>'), 'Request Processing Instruction is "&lt;?xml version="1.0" encoding="utf-8" ?&gt;"');
+
+    // The response body has to start with the xml processing instruction.
+    $this->assertIdentical(strpos($data, '<?xml version="1.0" encoding="utf-8" ?>'), 0, 'Response Processing Instruction is "&lt;?xml version="1.0" encoding="utf-8" ?&gt;"');
+    $this->assertIdentical($content_type, 'text/xml; charset=utf-8');
+  }
+
 }
diff --git a/xmlrpc_example/src/XmlRpcExampleTrait.php b/src/XmlRpcTrait.php
similarity index 89%
rename from xmlrpc_example/src/XmlRpcExampleTrait.php
rename to src/XmlRpcTrait.php
index 92baef4..ffac4fc 100644
--- a/xmlrpc_example/src/XmlRpcExampleTrait.php
+++ b/src/XmlRpcTrait.php
@@ -4,11 +4,11 @@
  * Contains XmlRpcControllerBase.php.
  */
 
-namespace Drupal\xmlrpc_example;
+namespace Drupal\xmlrpc;
 
 use Drupal\Core\Url;
 
-trait XmlRpcExampleTrait {
+trait XmlRpcTrait {
   /**
    * The XML-RPC server endpoint.
    *
diff --git a/tests/modules/xmlrpc_test/xmlrpc_test.module b/tests/modules/xmlrpc_test/xmlrpc_test.module
index b588978..4a5d8fb 100644
--- a/tests/modules/xmlrpc_test/xmlrpc_test.module
+++ b/tests/modules/xmlrpc_test/xmlrpc_test.module
@@ -143,6 +143,13 @@ function xmlrpc_test_simple_struct_return_test($number) {
 }
 
 /**
+ * Echoes http headers to XML-RPC clients.
+ */
+function xmlrpc_test_header_echo() {
+  return getallheaders();
+}
+
+/**
  * Implements hook_xmlrpc().
  */
 function xmlrpc_test_xmlrpc() {
@@ -156,6 +163,7 @@ function xmlrpc_test_xmlrpc() {
     'validator1.nestedStructTest' => 'xmlrpc_test_nested_struct_test',
     'validator1.simpleStructReturnTest' => 'xmlrpc_test_simple_struct_return_test',
     'messages.messageSizedInKB' => 'xmlrpc_test_message_sized_in_kb',
+    'test.headerEcho' => 'xmlrpc_test_header_echo',
   ];
 }
 
diff --git a/xmlrpc.inc b/xmlrpc.inc
index d37b38a..1be0693 100644
--- a/xmlrpc.inc
+++ b/xmlrpc.inc
@@ -400,7 +400,7 @@ function xmlrpc_request($method, array $args) {
   $xmlrpc_request->method = $method;
   $xmlrpc_request->args = $args;
   $xmlrpc_request->xml = <<<EOD
-<?xml version="1.0"?>
+<?xml version="1.0" encoding="utf-8" ?>
 <methodCall>
 <methodName>{$xmlrpc_request->method}</methodName>
 <params>
@@ -594,7 +594,7 @@ function _xmlrpc($url, array $args, array $headers = array()) {
   }
   $xmlrpc_request = xmlrpc_request($method, $args);
 
-  $headers['Content-Type'] = 'text/xml';
+  $headers['Content-Type'] = 'text/xml; charset=utf-8';
 
   try {
     $response = \Drupal::httpClient()->post($url, array(
diff --git a/xmlrpc.server.inc b/xmlrpc.server.inc
index d28f71e..aae1075 100644
--- a/xmlrpc.server.inc
+++ b/xmlrpc.server.inc
@@ -135,10 +135,10 @@ function xmlrpc_server_error($error, $message = FALSE) {
  *   A Response object.
  */
 function xmlrpc_server_output($xml) {
-  $xml = '<?xml version="1.0"?>' . "\n" . $xml;
+  $xml = '<?xml version="1.0" encoding="utf-8" ?>' . "\n" . $xml;
   $headers = array(
     'Content-Length' => strlen($xml),
-    'Content-Type' => 'text/xml',
+    'Content-Type' => 'text/xml; charset=utf-8',
   );
   return new Response($xml, 200, $headers);
 }
diff --git a/xmlrpc_example/src/Controller/XmlRpcExampleController.php b/xmlrpc_example/src/Controller/XmlRpcExampleController.php
index 40f4eaa..3682f3e 100644
--- a/xmlrpc_example/src/Controller/XmlRpcExampleController.php
+++ b/xmlrpc_example/src/Controller/XmlRpcExampleController.php
@@ -8,14 +8,14 @@
 namespace Drupal\xmlrpc_example\Controller;
 
 use Drupal\Core\Controller\ControllerBase;
-use Drupal\xmlrpc_example\XmlRpcExampleTrait;
+use Drupal\xmlrpc\XmlRpcTrait;
 
 /**
  * Controller methods for basic documentation pages in this module.
  */
 class XmlRpcExampleController extends ControllerBase {
 
-  use XmlRpcExampleTrait;
+  use XmlRpcTrait;
 
   /**
    * Constructs a page with info about the XML-RPC example.
diff --git a/xmlrpc_example/src/Form/XmlRpcExampleClientForm.php b/xmlrpc_example/src/Form/XmlRpcExampleClientForm.php
index 069eba9..0e2bd97 100644
--- a/xmlrpc_example/src/Form/XmlRpcExampleClientForm.php
+++ b/xmlrpc_example/src/Form/XmlRpcExampleClientForm.php
@@ -16,8 +16,7 @@ namespace Drupal\xmlrpc_example\Form;
 
 use Drupal\Core\Form\FormBase;
 use Drupal\Core\Form\FormStateInterface;
-use Drupal\Core\Url;
-use Drupal\xmlrpc_example\XmlRpcExampleTrait;
+use Drupal\xmlrpc\XmlRpcTrait;
 
 /**
  * Form demonstrating XML-RPC client.
@@ -27,7 +26,7 @@ use Drupal\xmlrpc_example\XmlRpcExampleTrait;
  */
 class XmlRpcExampleClientForm extends FormBase {
 
-  use XmlRpcExampleTrait;
+  use XmlRpcTrait;
 
   /**
    * {@inheritdoc}
diff --git a/xmlrpc_example/src/Tests/XmlRpcExampleTest.php b/xmlrpc_example/src/Tests/XmlRpcExampleTest.php
index 59964dc..1abe4e4 100644
--- a/xmlrpc_example/src/Tests/XmlRpcExampleTest.php
+++ b/xmlrpc_example/src/Tests/XmlRpcExampleTest.php
@@ -11,8 +11,7 @@
 namespace Drupal\xmlrpc_example\Tests;
 
 use Drupal\simpletest\WebTestBase;
-use Drupal\xmlrpc_example\XmlRpcExampleTrait;
-use Symfony\Component\Validator\Constraints\False;
+use Drupal\xmlrpc\XmlRpcTrait;
 
 /**
  * Test the XML-RPC examples.
@@ -21,7 +20,7 @@ use Symfony\Component\Validator\Constraints\False;
  */
 class XmlRpcExampleTest extends WebTestBase {
 
-  use XmlRpcExampleTrait;
+  use XmlRpcTrait;
 
   public static $modules = array('xmlrpc_example');
 
