How to get the context Id?


I would like to improve the monitoring of my integration. To do this, I need to get the contextID used in monitoring tables, from the IS service. I don’t find which methods I must use to get It. The Idea is to use the ContextID as a key to join my specific logging table with the webMethods one.

Do you have some idea to do this?

[IS 6.1 on windows]

Thanks a lot for your help


you cam try WmMonitor/wm.monitor.instance:getInstance from the WmMonitor-Package.
You need the InstanceID and you can get the ContextID
Hope that helps!



Thank you for your answer.

It’s true if I use the modeler, I can get the instanceID as an input of my service.

But unfortunately, I don’t use the process modeling approach. So I don’t know how to find the instanceID or contextID when I’m in the service.


Well, you can try this “unsupported” code:

String[] contextstack = InvokeState.getCurrentState().getAuditRuntime().getContextStack();

What you get is a stack containing 3 elements, rootcontext, parentcontext and contextid. Sometimes, the stack contains only 2 elements or 1 element:

  • rootcontext+prentcontextid in which case contextid=parentcontextid
  • or rootcontextid only, in which case, contextid=parentcontextid=rootcontextid, I think…

I am still wondering why these type of info are not yet public due to their usefullness…


It works well!

Thanks for your help.


What is the requiremnet for the above code ? Which classes does it require ?

I am really surprised why the API for getting the ContextID is not public. Considering , most of the services in the WmMonitor package require contextId as the input parameter. Unless one has the conntextID, there is no way one can use these services.

webMethods should make this API public ASAP.


I am using the EventManager to subscribe all exception events and the mail will be sent with the error.But i need the Service context id which has generated the error so tha it can be easy for republishing.

So for the above scenario how can i get the Context id?


Please run the following query in TOAD with the required Connection name and password

SELECT contextid, servicename,status FROM wmservice
WHERE servicename LIKE ‘%%’

Include the ServiceName between ‘%%’ .

This will look like ‘%Service_Name%’

So,if you know the Service Name ,then you can get the contextid.

Of course that will not work if the service has had errors before or has had multiple errors because you will get many context ids and not the one for the specific event that you are dealing with.

There seems to be no way to get the context id of the event using EventManager.

To enable effective searching of logged Services we need to Modify the Context ID and add transaction specific data to it, so that it becomes easy to search based on the Context ID and resubmit the right service from myWebMethods.

Can someone tell me how the same is done in webMethods 7.1

I have written a java service to get the Caller Service context id and i am able to get it when running the calling service directly.

But ,when the same java service is mapped in the Event Manager for Exception Event handling it is not getting invoked for some reasons … Any idea?