Total Pageviews

2017/09/10

[webMethods] How to invoke a Flow Service from a Java Service and get its output values

Problem
假設我要呼叫另外一個 flow service,此 flow service 沒有 input parameter,會回傳一個 output parameter,parameter name 為 isAlive

若我要透過 Java code 呼叫此 flow service,且取得其 output value 的話,該怎麼撰寫?


How-To

若呼叫 flow service 的方式是 synchronous,以下為 code snippet:
1
2
3
4
5
6
7
8
    try {
        // Invokes any service published on the server with the given input arguments.
        IData iData = Service.doInvoke("test.work", "Ping_Server", IDataFactory.create());
        // Returns a String representation of the value at the specified key.
        String isAlive = IDataUtil.getString(iData.getCursor(), "isAlive");
    } catch (Exception e1) {
     e1.printStackTrace();
    }



若呼叫 flow service 的方式是 asynchronous,以下為 code snippet:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
    try {
        // Invokes any service published on the server as a thread
        ServiceThread serviceThread = Service.doThreadInvoke("test.work", "Ping_Server", session, IDataFactory.create());
        // Returns the pipeline from the service running in this service thread.
        IData iData = serviceThread.getIData();
        // Returns a String representation of the value at the specified key.
        String isAlive = IDataUtil.getString(iData.getCursor(), "isAlive");
        loggerAsync(session, " is Alive = " + isAlive);
    } catch (Exception e) {
     e.printStackTrace();
    }

No comments: