1、首先启动web服务HelloService。见:http://healthandbeauty.iteye.com/blog/1614845
???? 把tomcat启动起来,就可以访问HelloService服务了。要做的工作的就通过Client类来访问Helloservice服务。具体实现代码过程见:http://healthandbeauty.iteye.com/blog/1614845
2、在elicpse里面新建一个类FaceClient 代码如下:
package net.chnbs.xfire.helloservice; import java.net.MalformedURLException; import java.net.URL; import org.codehaus.xfire.client.Client; import org.codehaus.xfire.transport.http.CommonsHttpMessageSender; /** *fileName: FaceClient.java *author:forrest li *time: 2012-7-31 下午08:07:13 **/ public class FaceClient { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Object[] result = { "aaaa" }; Client client = null; try { client = new Client(new URL("http://localhost:8080/hfa/services/HelloService?wsdl")); client.setProperty(CommonsHttpMessageSender.HTTP_TIMEOUT, "10000"); result = client.invoke("sayHello", result); System.out.print(result[0]); } catch (MalformedURLException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } } }
??Client只有一个参数,URL,这是Server服务器端的提供的webservice WSDL地址。然后调用invoke方法,第二个入参表示服务器端HelloServier方法sayHello方法的入参。
运行结果如下:
from service say hello!lizh
?