当前位置: 代码迷 >> Web前端 >> XFIRE_WEBSERVICES范例
  详细解决方案

XFIRE_WEBSERVICES范例

热度:139   发布时间:2012-08-21 13:00:21.0
XFIRE_WEBSERVICES实例

服务器端

?

接口

package com.server;

public interface IInfo {
 String sayHello(String words);
}

?

实现类?

?

package com.server;

public class InfoImpl implements IInfo{

	public String sayHello(String words) {
		return words;
	}

}

?

services.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xfire.codehaus.org/config/1.0">
<service>
		<name>test</name>
		<serviceClass>com.server.IInfo</serviceClass>
		<implementationClass>com.server.InfoImpl</implementationClass>
		<style>wrapped</style>
		<use>literal</use>
		<scope>application</scope>
</service></beans>

?

?

?

客户端调用

package com.client;
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 Client {
public static void main(String[] args) {
	String webserviceUrl="http://localhost:8083/webservice/services/test";
	Service serv=new ObjectServiceFactory().create(IInfo.class);
    XFireProxyFactory xfile=new XFireProxyFactory(XFireFactory.newInstance().getXFire());
    IInfo info=null;
    try{
		info = (IInfo)xfile.create(serv, webserviceUrl);
		String hello=info.sayHello("hello");
		System.out.println(hello);
    }catch(MalformedURLException e){}
}
}

?

?

?

?

详见附件,有疑问可以加我QQ:739921140

  相关解决方案