动态web服务客户端和java反射



Webservice包含:

ResultObj resultObj = getDocCountAction(RequestObj requestObj);

地点:

ResultObj and RequestObj contain "Long count" attribute.

因此,webservis方法获得输入计数并返回输出计数(我知道-这是无稽之谈:)

我想为"客户端。"调用("getDocCountAction", requestObj);"将值返回给responseObj。默认情况下,它返回Object[]。

// webservice client from remote wsdl
String wsdlURL = "http://localhost:8080/test/test.wsdl"
ClassLoader loader = Thread.currentThread().getContextClassLoader();
DynamicClientFactory factory = DynamicClientFactory.newInstance();
Client client = factory.createClient(wsdlURL, loader);
// accessing request object and setter method for count attribute and setting 666 value
Object requestObj = Thread.currentThread().getContextClassLoader().loadClass("pl.kago.stuff.RequestObj").newInstance();
Method setCount = requestObj.getClass().getMethod("setCount", Long.class);
setCount.invoke(requestObj, 666);

现在我有问题了。我知道我必须调用webservice方法并定义和访问responseObj。如何"绑定"webmethod与responseObj的结果?

// accessing response object and getter method for count attribute
Object responseObj = Thread.currentThread().getContextClassLoader() .loadClass("pl.kago.stuff.ResponseObj").newInstance();
Method getCount = responseObj.getClass().getMethod("getCount", Long.class);
client.invoke("getCount", responseObj);

下面访问webmethod

Object[] result = client.invoke("getCountAction", requestObj);

heh:)

对于其他有这种问题的人:

// webservice client from remote wsdl
String wsdlURL = "http://localhost:8080/test/test.wsdl"
ClassLoader loader = Thread.currentThread().getContextClassLoader();
DynamicClientFactory factory = DynamicClientFactory.newInstance();
Client client = factory.createClient(wsdlURL, loader);
// accessing request object and setter method for count attribute and setting 666 value
Object requestObj = Thread.currentThread().getContextClassLoader().loadClass("pl.kago.stuff.RequestObj").newInstance();
Method setCount = requestObj.getClass().getMethod("setCount", Long.class);
setCount.invoke(requestObj, 666);
// "binding" new result object to webmethod result
Object responseObj = Thread.currentThread().getContextClassLoader() .loadClass("pl.kago.stuff.ResponseObj").newInstance();
responseObj = client.invoke("getCountAction", requestObj);
// getting count value
Method getCount = responseObj .getClass().getMethod("getCount");
Object count = getCount.invoke(responseObj);

相关内容

  • 没有找到相关文章