IBM MQ Reason 2538(MQRC_ HOST_ NOT_ An example of error reason

Environment:.NET 4.0, MQ.NET client IBm.xMS (V2.0.0.3)
The test code is as follows:

       var factoryFactory = XMSFactoryFactory.GetInstance(XMSC.CT_WMQ);
       var _connFactory = factoryFactory.CreateConnectionFactory();

       _connFactory.SetStringProperty(XMSC.WMQ_HOST_NAME, "192.168.0.65");
       _connFactory.SetIntProperty(XMSC.WMQ_PORT, 1414);
       _connFactory.SetStringProperty(XMSC.WMQ_QUEUE_MANAGER, "XPP_QM");
       _connFactory.SetIntProperty(XMSC.WMQ_CONNECTION_MODE, XMSC.WMQ_CM_CLIENT);
       _connFactory.SetIntProperty(XMSC.WMQ_BROKER_VERSION, XMSC.WMQ_BROKER_V1);
       _connFactory.SetStringProperty(XMSC.CLIENT_ID, string.Empty);

       var conn = _connFactory.CreateConnection();
       conn.Start();

Error:
IBM. XMS. XMSException: CWSMQ0006E: method is called ConnectionFactory. Abnormal received during the CreateConnection: CompCode: 2, Reason: 2538
. During the execution of the specified method, another component throws an exception. For more information, see Linked Exceptions. .
in the IBM XMS. Client. WMQ. WmqConnectionFactory. CreateProviderConnection (XmsPropertyContext connectionProps)
in the IBM, XMS. Client. Impl. XmsConnectionFactoryImpl. The CreateConnection (String userID. String password)
in the IBM, XMS. Client. Impl. XmsConnectionFactoryImpl. The CreateConnection ()
in XRisk. MQ. MQConnection. Open (Boolean needLog) location e: \ xRisk4 – SRC \ XRisk MQ \ MQConnection cs: line number 314
Linked Exception : CompCode: 2, Reason: 2538
The real exception is reported in the following code.

IBM.WMQ.MQTCPConnection ---- < ParseLocalAddress(String) exit [o] rc=OK
IBM.WMQ.MQTCPConnection --- d Exception in method ConnectSocket(string,string,MQLONG)
IBM.WMQ.MQTCPConnection --- X System.Net.Sockets.SocketException (0x80004005): The requested name is valid and was found in the database, but it does not have the correct associated data being resolved for
at System.Net.Dns.InternalGetHostByAddress(IPAddress address, Boolean includeIPv6)
at System.Net.Dns.GetHostEntry(String hostNameOrAddress)
at IBM.WMQ.MQTCPConnection.ConnectSocket(String localAddr, String connectionName, Int32 options)
MQException CompCode: 2 Reason: 2538

The real reason is that in.NET 4.0, Microsoft changed the behavior of the interface Dns.GetHostEntry. When IP is used directly as a parameter, the report is not reported if the machine name or domain name is used.
The solution is as follows
1. Use ipAddres.tryparse () or Dns.Resolve(String) instead of Dns.GetHostEntry.
2. If you are using a third-party library and cannot modify the code, you can use the MACHINE name or domain name code for the IP. The above code can be changed to.

var factoryFactory = XMSFactoryFactory.GetInstance(XMSC.CT_WMQ);
var _connFactory = factoryFactory.CreateConnectionFactory();

_connFactory.SetStringProperty(XMSC.WMQ_HOST_NAME, "hostname");
_connFactory.SetIntProperty(XMSC.WMQ_PORT, 1414);
_connFactory.SetStringProperty(XMSC.WMQ_QUEUE_MANAGER, "XPP_QM");
_connFactory.SetIntProperty(XMSC.WMQ_CONNECTION_MODE, XMSC.WMQ_CM_CLIENT);
_connFactory.SetIntProperty(XMSC.WMQ_BROKER_VERSION, XMSC.WMQ_BROKER_V1);
_connFactory.SetStringProperty(XMSC.CLIENT_ID, string.Empty);

var conn = _connFactory.CreateConnection();
conn.Start();

Reference:
http://connect.microsoft.com/VisualStudio/feedback/details/561083/dns-gethostentry-behaves-differently-in-net-4-0-than-previous-versions
http://stackoverflow.com/questions/2714449/problem-with-system-net-dns-gethostentrydnsserver-on-net-4-0
https://www.ibm.com/developerworks/community/forums/html/topic?id=77777777-0000-0000-0000-000014538533#77777777-0000-0000-0000-000014538832

Reproduced in: https://www.cnblogs.com/jmax/p/3494320.html

Read More: