ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Calling .NET methods from ESQL procedure

Post new topic  Reply to topic
 Calling .NET methods from ESQL procedure « View previous topic :: View next topic » 
Author Message
grasher134
PostPosted: Mon Jun 20, 2016 5:39 am    Post subject: Calling .NET methods from ESQL procedure Reply with quote

Acolyte

Joined: 22 Oct 2014
Posts: 62

Hi,

Sorry for my English. I need to call .net method, stored in .dll, from esql procedure. In fact I wanted to create a small library of useful procedures that you don't have in esql.

I did it once already(I mean, that I used .NET procedure), so I repeated my steps as close as I could, but something just doesn't want to work....

I use mq for IO and I always get method not found error:

Code:
 An error was found when trying to resolve the .NET class and method ''ibmLib.ibmDate.DaysInMonth'' from assembly ''ibmLib'', which is referred to by the ESQL routine ''daysInMonth''.


I created new .NET project, showed the path to my dll, and then added reference to this project from my application. On deployment I can see my dll among the other resources of the execution group.

Below is esql code (external procedure is created outside from Module, don't know if it helps, I just copied from examples):

Code:
CREATE PROCEDURE daysInMonth (
       IN yearOfDate INTEGER NOT NULL,
       IN monthOfDate INTEGER NOT NULL,
       OUT daysInMonth INTEGER NULLABLE
       )
      LANGUAGE .NET
      EXTERNAL NAME "ibmLib.ibmDate.DaysInMonth"
      ASSEMBLY "D:\Visual Studio 2015 Projects\Projects\ibmLib\ibmLib\bin\Release\ibmLib.dll"
      APPDOMAIN "ibmLib";

DECLARE days INTEGER;
      CALL daysInMonth(EXTRACT(YEAR from CURRENT_TIMESTAMP), EXTRACT(MONTH from CURRENT_TIMESTAMP), days);
      
      SET OutputRoot.XMLNSC.result = days;




Here is the c# code. I've chosen classic desktop - class library.


Code:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ibmLib
{
    public class ibmDate
    {
        public static void DaysInMonth(int year, int month, out int daysInMonth)
        {
            daysInMonth = DateTime.DaysInMonth(year, month);
        }
    }
}



And the whole error message from user trace if it would help anyone.

Code:

2016-06-20 16:50:40.009752    15276   UserTrace   BIP2231E: Error detected whilst processing a message in node 'getTodaysPayments.MQ Input'.
                                       The message broker detected an error whilst processing a message in node 'getTodaysPayments.MQ Input'. The message has been augmented with an exception list and has been propagated to the node's failure terminal for further processing.
                                       See the following messages for details of the error.
2016-06-20 16:50:40.009768    15276   RecoverableException  BIP2230E: Error detected whilst processing a message in node 'getTodaysPayments.getTodays'.
                                       The message broker detected an error whilst processing a message in node 'getTodaysPayments.getTodays'. An exception has been thrown to cut short the processing of the message.
                                       See the following messages for details of the error.
2016-06-20 16:50:40.009772    15276   RecoverableException  BIP7458E: ('.daysInMonth', '1.1') : An error was found when trying to resolve the .NET class and method ''ibmLib.ibmDate.DaysInMonth'' from assembly ''ibmLib'', which is referred to by the ESQL routine ''daysInMonth''.
                                       The .NET method ''ibmLib.ibmDate.DaysInMonth'' from assembly ''ibmLib'' in location ''C:\ProgramData\Application Data\IBM\MQSI\components\myib9node\dabc3f64-5301-0000-0080-9e1c8fcc09ed\config\CLR\ibmLib\'' could not be found. Further messages are generated that explain the error in more detail.
                                       Correct the error in node ''.daysInMonth'', around line and column ''1.1'', then redeploy. Make sure that the assembly is present and accessible in the location specified. If the assembly is on a "mapped drive" or on a UNC path, make sure that the drive or path is visible in the session the execution group is running in. Also ensure that the broker's user id has permission to execute the assembly. If you are using a Configurable Service, ensure that its ApplicationBase is set to the correct location of the assembly.
2016-06-20 16:50:40.009780    15276   RecoverableException  BIP7477S: The .NET method ''ibmLib.ibmDate.DaysInMonth'' with '3' parameters could not be found in the assembly ''ibmLib''.
                                       The method must be public, static, and must have a signature that matches the broker datatype mappings for .NET types.
                                       Correct the method and redeploy.
Back to top
View user's profile Send private message
mqjeff
PostPosted: Mon Jun 20, 2016 6:12 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

Your method appears to be public but not static.
_________________
chmod -R ugo-wx /
Back to top
View user's profile Send private message
grasher134
PostPosted: Mon Jun 20, 2016 9:20 pm    Post subject: Reply with quote

Acolyte

Joined: 22 Oct 2014
Posts: 62

Code:
public static void DaysInMonth


But it is..
Back to top
View user's profile Send private message
grasher134
PostPosted: Mon Jun 20, 2016 9:56 pm    Post subject: Reply with quote

Acolyte

Joined: 22 Oct 2014
Posts: 62

Figured out that my node crashes on executing this procedure.

Code:
A summary of the Error follows:
An Unhandled Exception detected in process 11244, on thread 0x3114.
Type: EXCEPTION_ACCESS_VIOLATION (C0000005).
Address: 0033:00007FF90DA73368.
The thread could not read from memory address 0x0000000000000000.
Back to top
View user's profile Send private message
mqjeff
PostPosted: Tue Jun 21, 2016 3:59 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

grasher134 wrote:
Code:
public static void DaysInMonth


But it is..


I was looking at the class definition.

I've forgotten all of my .NET, but maybe EXCEPTION_ACCESS_VIOLATION means that the IIB process can't access the DLL due to file system permissions.
_________________
chmod -R ugo-wx /
Back to top
View user's profile Send private message
grasher134
PostPosted: Tue Jun 21, 2016 4:26 am    Post subject: Reply with quote

Acolyte

Joined: 22 Oct 2014
Posts: 62

I tried making a class static too, with the same result.

Quote:
means that the IIB process can't access the DLL due to file system permissions.


That was my thoughts exactly. I gave all permissions to my currents user and to every other user that were listed, but with no result.

I used .NET procedures on this pc before and it worked. I think something "broke" either in my IIB installation or in my node. As it happened several times before. Solution from IBM's support was always the same - clean install/new node.

I wrote opened a PMR. I'll write any updates here if there would be any.
Back to top
View user's profile Send private message
mqjeff
PostPosted: Tue Jun 21, 2016 4:56 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

It would be the user running the IIB EG.

This is likely a local user, rather than a domain user.

Unless you took steps to make it a domain user.
_________________
chmod -R ugo-wx /
Back to top
View user's profile Send private message
grasher134
PostPosted: Tue Jun 21, 2016 4:59 am    Post subject: Reply with quote

Acolyte

Joined: 22 Oct 2014
Posts: 62

It is the domain user. But he has admin rights.
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Tue Jun 21, 2016 1:06 pm    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20756
Location: LI,NY

Look at your code. Make sure that any exception that could be raised, including null pointer exceptions etc is being caught.
The procedure may return a failed value, the input value, or a different value, but it may not throw an exception.

Have fun
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
grasher134
PostPosted: Wed Jun 22, 2016 4:30 am    Post subject: Reply with quote

Acolyte

Joined: 22 Oct 2014
Posts: 62

fjb_saper wrote:
Look at your code. Make sure that any exception that could be raised, including null pointer exceptions etc is being caught.
The procedure may return a failed value, the input value, or a different value, but it may not throw an exception.

Have fun


I reduced my code to return 1; It didn't make any difference. Now I'm waiting an answer from IBM.
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Wed Jun 22, 2016 4:50 am    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20756
Location: LI,NY

err,,,,
I'm not familiar with the following construct in your signature:

public static void someMethod(int int1, int int2, out int int3)

Shouldn't that rather be:

public static int someMethod(int int1, int int2) ?

or even

public static int[] someMethod(int int1, int int2) ?

Have fun
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
grasher134
PostPosted: Wed Jun 22, 2016 5:09 am    Post subject: Reply with quote

Acolyte

Joined: 22 Oct 2014
Posts: 62

I used this as inspiration.

https://www.ibm.com/support/knowledgecenter/SSMKHH_9.0.0/com.ibm.etools.mft.doc/ak04960_.htm

And I already implemented the same schema once.
I needed to use hash in my project, so this is (a bit changed, ofc) code of my procedure, which I call from esql. And it works at the moment.



Code:

namespace ClassicHashLibrary
{
    public class MyMD5Class
    {

        public static byte[] GetHash(string inputString)
        {
            HashAlgorithm algorithm = SHA512.Create();
            return algorithm.ComputeHash(Encoding.UTF8.GetBytes(inputString));
        }

        public static void GetHashString(string inputString, string cif, out string outputString, out string hashedCif)
        {
           
            StringBuilder sb = new StringBuilder();
            foreach (byte b in GetHash(inputString))
                sb.Append(b.ToString("X2"));

            outputString = sb.ToString();

            StringBuilder sb1 = new StringBuilder();
            foreach (byte b in GetHash(cif))
                sb1.Append(b.ToString("X2"));

            hashedCif = sb1.ToString();

        }
    }
}


Back to top
View user's profile Send private message
mqjeff
PostPosted: Wed Jun 22, 2016 5:26 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

There's an old redbook that provides a lot of useful examples of .NET code from broker...
_________________
chmod -R ugo-wx /
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Calling .NET methods from ESQL procedure
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.