使用工具:MyEclipse8.5+tomcat6
1. file-->new Web Service Project,填好项目名称,framework选择XFire,如图一
图一
2. next-->next选择下面三项如图二
图二
3.选择finish,出现如下所示项目如图三
图三
4.在src下新建package(webservice),接口HelloWorld。其实现类HelloWorldImpl如图四
图四
5.impl代码
package webservice; publicclass HelloWorldImpl implements HelloWorld { public String sayHelloWithParameter(String str) { // Todo Auto-generated method stub return"hello"+str; } publicvoid sayHelloWithoutParameter() { // Todo Auto-generated method stub } }
6.配置WebService下services.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://xfire.codehaus.org/config/1.0"> <service> <name>Hello</name> <namespace>http://localhost:8080/Hello/</namespace> <serviceClass>webservice.HelloWorld</serviceClass> <implementationClass>webservice.HelloWorldImpl</implementationClass> </service> </beans>
7.输入http://localhost:8080/Hello/services如图五
图五
8.点击wsdl,如图六
图六
9.test代码
package webservice; import java.net.MalformedURLException; import org.codehaus.xfire.XFireFactory; import org.codehaus.xfire.client.XFireProxyFactory; import org.codehaus.xfire.service.Service; import org.codehaus.xfire.service.binding.ObjectServiceFactory; public class Test { /** * @param args */ public static void main(String[] args) { Service srvcModel = new ObjectServiceFactory().create(HelloWorld.class); XFireProxyFactory factory = new XFireProxyFactory(XFireFactory.newInstance().getXFire()); System.out.println(factory); String helloWorldURL = "http://localhost:8080/Hello/services/Hello"; try { HelloWorld srvc = (HelloWorld) factory.create(srvcModel,helloWorldURL); String result = srvc.sayHelloWithParameter("rrr"); System.out.println(result); } catch (MalformedURLException e) { // Todo Auto-generated catch block e.printstacktrace(); } } }
org.codehaus.xfire.client.XFireProxyFactory@c24c0
hellorrr
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。