MQ ERROR Code 2035 and 2063 - ibm-mq

Whenever we try to connect to websphere MQ server through .NET Application we get Error message code 2063.Also some time 2035.We tried to connect to MQ Server using both XMS.NET and plain old amsmqdnet.dll..how authentication/authorization works when we connect to MQ server from .net applicatio?please guide...
using System;
using IBM.XMS;
XMSFactoryFactory factoryFactory;
IConnectionFactory cf;
// Get an instance of factory.
factoryFactory = XMSFactoryFactory.GetInstance(XMSC.CT_WMQ);
// Create WMQ Connection Factory.
cf = factoryFactory.CreateConnectionFactory();
// below properties r set
//cf.SetStringProperty(XMSC.WMQ_HOST_NAME, "hostname");
// cf.SetIntProperty(XMSC.WMQ_PORT,0);
// cf.SetStringProperty(XMSC.WMQ_CHANNEL, "channel");
//cf.SetIntProperty(XMSC.WMQ_CONNECTION_MODE, XMSC.WMQ_CM_CLIENT);
// cf.SetStringProperty(XMSC.WMQ_QUEUE_MANAGER, "queuemanager name");
// cf.SetStringProperty(XMSC.WMQ_QUEUE_NAME, "queuename");
// Create connection.
var mqConnection = cf.CreateConnection();

Related

Open Api 3.0 Swagger application with Visual Studio 19 - database connection problem

I have to make application for .NET5.0. (Core). I have installed packages Devart.Data (5.0.2658) and Devart.Data.Oracle(9.14.1234).
I use 32 bits oracle client in my computer.
I have switched my application to x86 mode.
I need to connect to a Oracle 12 server.
Here is my code:
[Route("GetMyData")]
[HttpGet]
public List<Cis_titul_pred> GetCiselnik()
{
List<DataModule.BO.Cis_titul_pred> testlist =
DataModule.DAL.Cis_titul_predDB.Instance.GetList();
return testlist;
}
public List<Cis_titul_pred> GetList()
{
List<Cis_titul_pred> cis_titul_predList = null;
using (OracleConnection oraConnect = new OracleConnection(AppConfig.ConnectionString))
{
OracleCommand oraCommand = new OracleCommand(selectList, oraConnect);
oraCommand.CommandType = CommandType.Text;
oraConnect.Open();
using (OracleDataReader oraReader = oraCommand.ExecuteReader())
{
if (oraReader.HasRows)
{
cis_titul_predList = new List<Cis_titul_pred>();
while (oraReader.Read())
{
cis_titul_predList.Add(FillCis_titul_pred(oraReader));
}
}
oraReader.Close();
}
oraConnect.Close();
}
return cis_titul_predList;
}
When I created .NET5.0 Desktop (WinForms) application , everything worked properly - I could connect to Oracle server and read data.
When I created .NET5.0 WEB application , everything worked properly - I could connect to Oracle server and read data.
When I created .NET5.0 OpenApi application , I got error message "Devart.Data.Oracle.OracleException (0x80004005): Server did not respond within the specified timeout interval
at Devart.Data.Oracle.dp.a(cj A_0, di A_1)
at Devart.Data.Oracle.OracleInternalConnection..ctor(cj connectionOptions, OracleInternalConnection proxyConnection)
at Devart.Data.Oracle.ci.a(ae A_0, Object A_1, DbConnectionBase A_2) Etc. ... Etc..."
I use the same code to connect to the Oracle server in all three applications
I tried change target framewor to NET.Core 3.0, or NET.Cre 3.1, but without success.
Any ideas?
What can I do?
What do you mean by .NET5.0 OpenApi application? It's the same architecture with .net5 web... Please check If you have a correct and same connection string in your appSettings.json file. Also consider using dependancy injection instead of creating OracleConnection instance inside controllers

IBM Watson Conversation Service Using Proxy settings from Java API

I have developed a conversation service using IBM Watson and deployed. I am able to access my service using the IBM Watson API explorer. I tried connecting the service using a Java API as explained in https://developer.ibm.com/recipes/tutorials/integration-of-ibm-watson-conversation-service-to-your-java-application/ I am working on a corporate network, so using proxy to access internet. Now I am not able to access the service from my Java API. I am getting below error.
Exception in thread "main" java.lang.RuntimeException: java.net.ConnectException: Failed to connect to gateway.watsonplatform.net/169.48.66.222:443
at com.ibm.watson.developer_cloud.service.WatsonService$1.execute(WatsonService.java:182)
at com.chat.CustomerChat.conversationAPI(CustomerChat.java:47)
at com.chat.CustomerChat.main(CustomerChat.java:32)
Caused by: java.net.ConnectException: Failed to connect to gateway.watsonplatform.net/169.48.66.222:443
at okhttp3.internal.io.RealConnection.connectSocket(RealConnection.java:187)
at okhttp3.internal.io.RealConnection.buildConnection(RealConnection.java:170)
at okhttp3.internal.io.RealConnection.connect(RealConnection.java:111)
at okhttp3.internal.http.StreamAllocation.findConnection(StreamAllocation.java:187)
at okhttp3.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:123)
at okhttp3.internal.http.StreamAllocation.newStream(StreamAllocation.java:93)
at okhttp3.internal.http.HttpEngine.connect(HttpEngine.java:296)
at okhttp3.internal.http.HttpEngine.sendRequest(HttpEngine.java:248)
at okhttp3.RealCall.getResponse(RealCall.java:243)
at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:201)
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:163)
at okhttp3.RealCall.execute(RealCall.java:57)
How do we set proxy connection in IBM watson Connection service?
My code:(Modified the user credentials and workspace id here)
ConversationService service = new ConversationService("2017-05-26");
service.setUsernameAndPassword("dfgdfg-578a-46b6-55hgg-ghgg4343", "ssdsd455gfg");
MessageRequest newMessage = new MessageRequest.Builder().inputText(input).context(context).build();
String workspaceId = "fgfdgfgg-ce7a-422b-af23-gfgf56565";
MessageResponse response = service.message(workspaceId, newMessage).execute();
Not completely sure about work around for Java, but when i had similar issue with Node, i had to set up proxy variables and that helped. I would recommend you to give a try by setting up proxy variables in eclipse and JVM. And also i think this Java file must be helpful.
After going though IBM API documentation I found below method to set the proxy. It should work.
HttpConfigOptions config = new HttpConfigOptions
.Builder()
.proxy(new Proxy(Proxy.Type.HTTP,
new InetSocketAddress("<Proxy IP>", <Proxy Port>)))
.build();
service.configureClient(config);
I implemented this code with Java-sdk 6.14.0. IBM has discontinued ConversationService package and deprecated Conversation package in this version of SDK. Instead Assistant package has been introduced. My working code is as below.
Assistant service = null;
Context context = null;
if (watsonUser.equalsIgnoreCase(APIKEY_AS_USERNAME))
{
IamOptions iamOptions = new IamOptions.Builder().apiKey(watsonApikey).build();
service = new Assistant(watsonVersion, iamOptions);
}
else
{
service = new Assistant(watsonVersion, watsonUser,watsonPassword);
}
service.setEndPoint(watsonUrl);
if(watsonProxy != null)
{
HttpConfigOptions config = new HttpConfigOptions
.Builder()
.proxy(new Proxy(Proxy.Type.HTTP,
new InetSocketAddress(watsonProxyIP, watsonProxyPort)))
.build();
service.configureClient(config);
}
String workspaceId = watsonWorkspace_id;
InputData input = new InputData.Builder(inputStr).build();
MessageOptions options = new MessageOptions.Builder(workspaceId)
.context(context)
.input(input)
.build();
MessageResponse response = service.message(options).execute();
context = response.getContext();
I have checked the code with Conversation package based implementation. It worked. I couldn't checked with code given in the question as ConversationService package is no more in the current SDK.

JMS and IBM WebSphere not generating COD

I am creating an application that consumes messages from a MQ using JMS. My MQ manager is IBM WebSphere MQ and I am using the IBM jms implementation to consume the messages.
The messasges are coming and going fine. I receive the messages from the other part and I can send messages to them. The problem is that they are not receiving the COD after I consume the message from the queue. They receive the COA, but no COD.
Here is my receive message code:
public byte[] readMsgFromClient() throws JMSException {
byte[] message = null;
QueueReceiver reader = null;
try {
connection = getQueueConnection();
connection.start();
session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = session.createQueue(config.getQueueRsp());
((MQQueue) queue).setTargetClient(JMSC.MQJMS_CLIENT_NONJMS_MQ);
reader = session.createReceiver(queue);
JMSBytesMessage byteMessage = (JMSBytesMessage) reader.receive(3000);
if (byteMessage != null) {
message = new byte[(int) byteMessage.getBodyLength()];
byteMessage.readBytes(message);
}
} finally {
if (reader != null) {
reader.close();
}
if (session != null) {
session.close();
}
if (connection != null) {
connection.close();
}
}
return message;
}
Do I have to manually send the COD? DO I have to configure my WebSphere to automatically send the COD? Do I have to notify the WebSphere that my application has consumed the message?
The COD messages are probably ending up the the dead letter queue (DLQ) with an RC (Reason Code) of 2035 (not authorized).
Here is another of those things you learn the hard way:
COA messages are generated under the queue manager's UserId
COD messages are generated under the UserId of the sender's message.
If the sending application's UserId is appl001 then the COD will be generated using the UserId of appl001. If that UserId does not have permission to write to the particular queue then the message will end up in the DLQ.
Generally, the permission issue happens when the sender application is connected to 1 queue manager and the receiver application is connected to another queue manager. i.e. messages are hoping between queue managers.
Hence, the sender's UserId does not have permission to put a message on the remote queue manager.
As stated by #Roger, the permissions to put the COD are based on the UserId in the MQMD of the message that is sent.
If you do not want to add the remote user to your local system you can use the itsoME exit provided in the IBM Redbook "Secure Messaging Scenarios with WebSphere MQ". The latest version is found under the "Additional Material" link.
With this exit you need to have a MCAUSER set on your RCVR or RQSTR channel and configure that channel with the following attributes:
MSGEXIT('itsoME(MsgExit)')
MSGDATA('MCA/')
The result is that UserIdentifier field of the MQMD will be changed to the value of the MCAUSER that is configured on the channel. You would then give that MCAUSER +put and +passid to the XMITQ that returns to the remote queue manager.
The exit can be used for other things such as removing the reporting options if you do not want to allow COA/COD.

MQQueueManager: What to expect from isConnected state after creation, during use?

I inherited this lovely bit of code below.
The way I read it the developer makes three assumptions:
An MQQueueManager instance is not necessarily created in a state where isConnected() returns true
If it is created in state isConnected() == false, the state might change "later", hence the timeout code
If you try to create an access queue from a disconnected MQQueueManager, it will not throw an exception.
What I would expect is that an MQQueueManager instance is created in state isConnected() == true, that this state might change later (network failure etc), and that this state change (isConnected() == false) would cause an operation on the queue to fail with an MQException.
The documentation is delightfully silent on these points, except to note that the only way to reconnect to a queue after manually disconnecting the MQQueueManager is to create a new instance of MQQueueManager.
Who can set me straight here?
qMgr = new MQQueueManager( qManager );
// Set up the options on the queue we wish to open...
// Note. All WebSphere MQ Options are prefixed with MQC in Java.
final int openOptions = MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_OUTPUT;
// Now specify the queue that we wish to open,
// and the open options...
queue = qMgr.accessQueue( queueName, openOptions );
// Set the get message options...
final MQGetMessageOptions gmo = new MQGetMessageOptions(); // accept the
// defaults
gmo.options = MQC.MQGMO_WAIT;
gmo.waitInterval = 1000;
connectionStatus = CONNECTING;
int timeOutCounter = 0;
while(!qMgr.isConnected()) {
InboundMsgTask.sleep(1000);
timeOutCounter++;
if(timeOutCounter > 4) {
connectionStatus = TIME_OUT;
return;
}
}
connectionStatus = CONNECTED;
Instead of checking the IsConnected==True, it is better to go ahead make the actual MQ .NET method call (Get, Put etc). If the connection is broken these calls would throw a connection broken execption (MQRC 2009). Remember the IsConnected could be True before a MQ method is called but it can change during the execution of a MQ method. Your code needs to handle the connection broken exception and call the MQQueueManager.Disconnect method and then re-establish the connection. The Disconnect call would free up any resources allocated and close all gracefully any queue manager objects that were opened. Ignore any exception thrown by the Disconnect method.
If you are using MQ v7.1 or v7.5, then the .NET client can automatically reconnect to queue manager if it detects connection errors. You will need to enable the automatic reconnect option. Please see the MQ InfoCenter.
EDIT:
A new MQQueueManager() will return an instance of MQQueueManager class if connection to queue manager is successfully established. In case of errors, a MQExceptionwill be thrown. There is no need to wait for connection to complete as MQQueueManager constructor is a blocking call.

Failed to connect to an IPC Port: The system cannot find the file specified

In my .net 2.0 application Remote object suddenly destroyed and thrown the below exception.
"Failed to connect to an IPC Port: The system cannot find the file specified."
I have IPC remoting server and which create a singleton object.
i have override the InitializeLifetimeService() method and returns null for infinite lifetime.
server and client applications are working fine but some times we got the above exception.
serverCode:
//create and register the processheartbeat.
BinaryServerFormatterSinkProvider serverprovider = new BinaryServerFormatterSinkProvider();
serverprovider.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
//Hosts the Heartbeat object and registers it.
processHeartbeatChn = new IpcServerChannel("HeartbeatChannel", "localhost:" + applicationHeartbeatPort, serverprovider);
//registers the channel
ChannelServices.RegisterChannel(processHeartbeatChn, false);
//register the service
RemotingConfiguration.RegisterWellKnownServiceType(typeof(Heartbeat),
appName, WellKnownObjectMode.Singleton);
ClientCode:
string uri = string.Format(CultureInfo.InvariantCulture,"ipc://localhost:{0}/{1}", applicationHeartbeatPort, appName);
//get the Heartbeat object
remoteHeartbeat = (Heartbeat)Activator.GetObject(typeof(Heartbeat), uri);
any hot fix is there to resolve this problem?
can any one help me an this?

Resources