2020-05-13

[AgentFlow]呼叫WebService

// targetAddr 放 AgentflowWebServices 或者其他 WebServices 的 service URL
var targetAddr = "http://127.0.0.1:8080/WebAgenda/webservice/AgentflowWeb.jws";

// 傳回 mems 是 JavaScript Array, 不是 Vector
var mems = WS_getAllMember();
for(var i=0; i<=10; i++){
var msgList = Form.getDataInvalidMsgList();
msgList.add("User " +  i + ": " + mems[i][2] );
Form.setDataInvalidMsgList(msgList);
}

// 傳回 memRet 是 JavaScript Array, 不是 Vector
var memRet = WS_getMember("MEM20021561425789980");
for(var i=0; i<=10; i++){
var msgList = Form.getDataInvalidMsgList();
msgList.add("UserField " +  i + " = " + memRet[i] );
Form.setDataInvalidMsgList(msgList);
}

// 這是重點,直接用 WebServices 基本 library,來呼叫 WebServices
function WSCall(url, mname, args)
{
var ep = new Packages.java.net.URL(url);
var svc =  new Packages.org.apache.axis.client.Service();
var call = svc.createCall();
var ns = "http://schemas.xmlsoap.org/soap/encoding/";
var qname =  new Packages.javax.xml.namespace.QName(ns, mname);
call.setTargetEndpointAddress(ep);
call.setOperationName(qname)
return call.invoke(args);
}

//呼叫看看,這是不傳入參數的例子
function WS_getAllMember()
{
var args = new Array();
var ret = WSCall(targetAddr, "getAllMember", args );
return ret;
}

function WS_getMember(uid)
{
var args = new Array();
args[0] = uid;
var ret = WSCall( targetAddr, "getMember", args );
return ret;
}

沒有留言:

張貼留言