Dynamic Call of flow services

How to call Flow services dynamically within other Flow services.

Thanks…

Write a java service for com.wm.app.b2b.server.Service.doInvoke API. Use this java service to dynamically invoke any other service by passing the service name.

Any other way out without using JAVA…

I am able to call dynamically, but by a REMOTE INVOKE, where the local BC server is created as a REMOTE server.

Still looking around for other way outs !!!

James : Could you post the code for the solution you gave. Thanks…

Bhavani Shankar

Bhavani,

If you are working with Ver 6.0, they have a new package WMUtilities. Look for the Javautilities folder, it has a service called ‘localinvoke’. You can use this for dynamic invoke.

If you dont have this package, I can send you the code for it.

Manohar

If you want to receive the output of that invoked service add this code.

IData myDateConversion = IDataFactory.create();
IDataCursor tmpHashCursor = myDateConversion.getCursor();
tmpHashCursor.last();
tmpHashCursor.insertAfter(“inString”, inString);
tmpHashCursor.insertAfter(“currentPattern”, currentPattern);
tmpHashCursor.insertAfter(“newPattern”, newPattern);
tmpHashCursor.destroy();
IData outIData = Service.doInvoke(“pub.date”, “dateTimeFormat”, myDateConversion);
tmpHashCursor = outIData.getHashCursor();
tmpHashCursor.first (“value”);
inString = (String) tmpHashCursor.getValue();
tmpHashCursor.destroy();

HTH,
Muru.

May be I am over enthu, I didnt look at what merge was doing. I am sorry about that.

Thanks,
Muru.

Just a little heads up. The position of the cursor when a positioning method fails is not defined, so if there ever could be a situation when “value” does not exist in the pipeline, the following code could return unexpected results:

tmpHashCursor.first (“value”);
inString = (String) tmpHashCursor.getValue();

should be:

if (tmpHashCursor.first (“value”))
inString = (String) tmpHashCursor.getValue();

or:

inString = IDataUtil.getString(tmpHashCursor, “value”);

Manohar,

Where does the WMUtilities package come from? I do not seem to have it in my installation…

Thanks

The service is available in WMEDI package under the following location.

wm.b2b.edi.util:invoke

Thanks for all the help given…

Cheers!
Bhavani Shankar

Hi

How do I invoke a remote service using Service.doInvoke? How to specify the remote server name?

Thanks
Venkat

Venkat,
You don’t :-), at least not directly. I’d suggest you use Service.doInvoke to call pub.remote:Invoke. You can pass it a remote server alias, your service’s name and inputs. HTH.

Michael,

Can you provide usage code snippet for me? I’m confused with the parameters for the Service.doInvoke

Thanks,
Venkat

Venkat,

Check this out:
IData output = Service.doInvoke(folderName, serviceName, pipeline).

This is just a sample snippet.

HTH.

RMG,

IData output = Service.doInvoke(“pub.remote”,“Invoke”,pipeline)

Now where do I specify the server name alias and myremotefolder.remoteServiceName.

Can someone throw ray of light !!

Thanks
Venkat

I am not sure about how the remote invocation works in your case.

The code snippet which i have posted above will work dynamically calling the service on local server.

And please take a look into the webMethods JavaAPI reference and check under the Service class,which will show up all kinds of doInvoke().

HTH.

Ah, I see. I haven’t done this in Java, only in Flow. But you’d need to explicitly specify the input for pub.remote:Invoke, instead of “pipeline”. Not quite sure how to do that in Java, since there would be multiple inputs in one parameter. Maybe create a string variable to hold the inputs?:

String remInvokeInputs = “<remote>, <folder.folder:service>”;
IData output = Service.doInvoke(“pub.remote”, “Invoke”, remInvokeInputs);

Anybody know if that would work?

I think the correct way would be to use the com.wm.app.b2b.client.TContext class to establish the connection to the remote server and do your invocation. Basically, you want your server to act as a client to the remote server.

I do not have a code sample, but this should help.

David,

You are right !!

I found the sample code in http://advantage.webmethods.com and I’m pasting the same here.

For those who want to invoke a remote service using webM Java API
////////////////////////////

String host = “remoteserver:5555”;
String user = “remoteuser”;
String pass = “password”;
String ifc = “folder”;
String svc = “serviceName”;

Context c = null;
try {
c = new Context();

c.connect(host, user, pass);

ValuesEmulator.put(pipeline, “result”, c.invoke(ifc, svc, IDataFactory.create()));

c.disconnect();

} catch (Exception e) {
if (c != null) {
try {
c.disconnect();
} catch (Exception ee) {
// ignore this…
}
}
throw new ServiceException("Error during invoke: " + e.getMessage());
}

///////////////////////////
This code doesn’t fetch output from the remote service.

Hope this helps…

Thanks everybody !!
Venkat

Take a quick look at the 5th and 6th postings on this thread. This will give you the generic form of how to set pipeline variables for a service invocation. The only other thing that you would need to do is take a look at the service signature your target service (i.e. pub.remote:invoke).

Inputs that appear at the top level are inserted directly into your new pipeline. Nested inputs need to be contained in another IData container. There’s a sample of creating a nested IData input for a service in the WmSamples package; take a look in the folder sample.idata at the service createNestedIData.

hth

Using the Context class is fine too. No transactions though… The code should look quite the same…