WebService初学

使用工具:MyEclipse8.5+tomcat6

1.      file-->new Web Service Project,填好项目名称,framework选择XFire,如图一

图一

2.      next-->next选择下面三项如图二

图二

3.选择finish,出现如下所示项目如图三

图三

4.src下新建packagewebservice),接口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.配置WebServiceservices.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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值