XFire的HelloWorld!

之前有写过helloworld可是写得很差,我想一定有很多人看不懂。现在我将步骤截图下来

1.创建服务器端,创建一个web Services Project

2.创建一个接口和一个实现类

public interface IWearther {
    /**
     * @return 返回字符串,用于显示天气
     */
    public String wearther();
}

public class IWeartherImpl implements IWearther {

    /**
     * @return 返回字符串,用于显示天气
     */
    public String wearther() {
        String result = "根据一系列处理得到当前天气为阴天!";
        return result;
    }

}

3.修改webServices文件夹下的services.xml

    <service>
        <name>Wearther</name>
        <namespace>www.jungle.com/Weather</namespace><!-- 网站域名+上面节点name -->
        <serviceClass>com.jungle.IWearther</serviceClass><!--  接口 -->
        <implementationClass>
            com.jungle.IWeartherImpl
        </implementationClass><!-- 实现类 -->
    </service>

PS:简单的服务器就创建完成了,



4.创建客户端,这里要注意的是创建的是WebProject

首先引入需要的jar包:

5.在客户端创建接口,名称不用和服务器端一样,但是方法要和服务器端一模一样。

public interface IWeartherClient {
    
    /**
     * @return 返回字符串,用于显示天气,方法要和服务器端的方法完全一样。
     */
    public String wearther();
}

6.测试类:

import java.net.MalformedURLException;

import org.codehaus.xfire.client.XFireProxyFactory;
import org.codehaus.xfire.service.Service;
import org.codehaus.xfire.service.binding.ObjectServiceFactory;

//http://fxk2006.iteye.com/blog/618802
public class TestMain {
    public static void main(String[] args) throws MalformedURLException {
        Service service = new ObjectServiceFactory().create(IWeartherClient.class);

        // 地址 + 服务器端的<url-pattern>/services/*</url-pattern> + 服务器端的services.xml中的<name>Wearther</name>
        String url = "http://localhost:8000/XFireTest/services/Wearther";
        IWeartherClient client = (IWeartherClient) new XFireProxyFactory().create(service, url);// 得到本地的接口
        System.out.println(client.wearther());
    }
}




  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值