title: Service Broker behind NAT and port forwarding results in "corrupted message has been received" error
body: <p>Sending message via SQL Server Service Broker from one machine to another.</p>
  
  <ul>
  <li><p><strong>Sender</strong> - Windows Server 2012 R2 with SQL Server 2014 12.0.4213.0 Standard over NAT that has port forwarding for Service Broker from public IP:port to local SQL Server IP:port. Let's say, for example, the port is <code>26223</code> and it forwards to SQL Server <code>4022</code>.</p></li>
  <li><p><strong>Receiver</strong> - CentOS 7 with SQL Server 2017 RC2 Express as web server with the same specific port opened for Service Broker. (updating to latest SQL Server CU - 14.0.3030.27 did not help)</p></li>
  </ul>
  
  <p>I sent message from Sender to Receiver and firstly got error in <code>sys.transmission_queue</code> about wrong alghoritm, then I found out that I have encryption key alghoritms different on sender's and receiver's endpoints and changed receiver endpoint key encryption alghoritm to match sender's.</p>
  
  <p>After that, the message I sent appeared in <code>sys.transmission_queue</code> with another error - <code>Service Broker/Database Mirroring network protocol error occurred.</code> In SQL Profiler I found more details:</p>
  
  <blockquote>
    <p>Broker:Corrupted Message - A corrupted message has been received. The binary message preamble is malformed.</p>
  </blockquote>
  
  <p>On the Receiver side SQL Profiler shows that:</p>
  
  <blockquote>
    <p>Audit Broker Login: 4 - Negotiate Failure - An error occurred while receiving data: '996(Overlapped I/O event is not in a signaled state.)'.</p>
    
    <p>Audit Broker Login: 5 - Authentication Failure</p>
  </blockquote>
  
  <p>Sometimes I also got that error at Receiver side in addition to previous:</p>
  
  <blockquote>
    <p>Audit Broker Login: 4 - Negotiate Failure - An error occurred while receiving data: '24(The program issued a command but the command length is incorrect.)'.</p>
  </blockquote>
  
  <p>I have only one message for that instance waiting in <code>sys.transmission_queue</code> on Sender side.</p>
  
  <p><strong>UPDATE:</strong>
  I used <em>ssbdiagnose</em> utility and here is what it says:</p>
  
  <p><code>D  29835 MainServer   MainDatabase         Messages on conversation handle 13c07ab1-6b8d-e711-80c5-002590cb2a25 (conversation id 3a7d0dd0-c957-4fe8-a98e-1cb56713023c) from service sbSenderService to service sbReceiverService cannot be transmitted dues to the following problem: Service Broker/Database Mirroring network protocol error occurred.</code></p>
  
  <p><code>An internal exception occurred: No such host is known</code></p>
  
  <p><code>D  29933 WebServer     WebDatabase          The routing address TCP://[NAT ip address was here]:26223 for service sbSenderService does not match any of the IP addresses for MainServer</code></p>
  
  <p><code>An internal exception occurred: Value cannot be null.
  Parameter name: value</code></p>
  
  <p><code>An internal exception occurred: No such host is known
  P  29945               Cannot parse the routing address: unknown</code></p>
  
  <p>So, the new error came into play: <strong>The routing address TCP://[NAT ip address was here]:26223 for service sbSenderService does not match any of the IP addresses for MainServer</strong></p>
  
  <p>As I understand it, my MainServer (Sender) does not know the NAT IP Address that is in TCP headers and marks that TCP package malformed, right? How to fix it?</p>
  
  <p><strong>UPDATE2:</strong> we set VPN tunnel between servers and the same errors still exists. The test CentOS server had all ports opened and no Selinux. For now I assume that Service Broker does not work between CentOS and Windows.</p>
  
  <p><strong>UPDATE3:</strong> updating to latest SQL Server CU on CentOS - 14.0.3030.27 did not help</p>