方法来完成测试,该类的详细内容如下所示:
package test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import webservice.HelloWorld;
/**
* HelloWorld的webservice的测试类.
*/
public class WebServiceClientTest {
HelloWorld helloWorld = null;
public static void main(String[] args) {
WebServiceClientTest test = new WebServiceClientTest();
test.testClient();
}
public void testClient() {
ApplicationContext ctx = new ClassPathXmlApplicationContext(
"client.xml");
helloWorld = (HelloWorld) ctx.getBean("testWebService");
System.out.println(helloWorld.sayHelloWorld("阿蜜果"));
}
}
在启动webservice_helloworld工程的情况下,运行WebServiceClientTest类,可看到控制台包含如下信息:
hello,阿蜜果
由此可看出调用Web Service成功。
四.总结
与Axis相比,在实施Web Service时XFire更加简洁高效,并且XFire对Spring提供了强大的支持,可以非常方便地在Spring中使用XFire实施Web Service,因此XFire在短短的时间里成为了受Web Service开发者喜爱的框架。
XFire为客户端提供了多种访问Web Service的方式,如果可以获取客户端的窄接口类,则可以采用窄接口类调用Web Service。如果仅能获取WSDL,XFire也可以采用动态反射的机制调用Web Service。XFire为Eclipse提供了一个可以根据WSDL生成客户端存根代码的插件,相信XFire也将为其它非Java语言提供类似的插件。
技术可用性的一个很大的标准是它是否方便测试,XFire提供多种方式进行Web Service的测试,简单方便,给Web Service开发人员的测试工作带来了福音。
在本文中,笔者通过一个简单的helloWorld的Web Service例子,详细地说明了用XFire+Spring构建Web Service时配置文件的相关配置,以及测试的各种方法,也让读者见识了XFire与Spring的无缝集成,希望对读者学习XFire有点帮助。