xfire 做webservice 备忘
1、接口加标注
@WebService(targetNamespace="http://www.geostar.com.cn/geoglobe")
public interface IGeoSearch {
public String search(@WebParam(name="keyword")String keyword,@WebParam(name="start")int start,@WebParam(name="maxFeature")int maxFeature);
public String go(@WebParam(name="key")String k);
}
2、接口实现类
@WebService(serviceName="GeoSearch")
public class GeoSearchImpl implements IGeoSearch {
public String search(String keyword,int start,int maxFeature){
IWFSService wfs=new WFSServiceImpl();
Document out=null;
try{
out=wfs.search(keyword, start, maxFeature);
}
catch(DocumentException e){
e.printStackTrace();
}
return out.asXML();
};
public String go(String k){
return "welcome "+k;
};
}
3 配置 service.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans>
<service xmlns="http://xfire.codehaus.org/config/1.0">
<name>suggest</name>
<namespace>GeoGlobe</namespace>
<serviceClass>cn.geostar.inter.suggest.Isuggest</serviceClass>
<implementationClass>cn.geostar.impl.suggest.ImplSuggest</implementationClass>
</service>
<service xmlns="http://xfire.codehaus.org/config/1.0">
<name>GeoSearch</name>
<serviceClass>cn.geostar.inter.suggest.IGeoSearch</serviceClass>
<implementationClass>cn.geostar.impl.suggest.GeoSearchImpl</implementationClass>
<serviceFactory>org.codehaus.xfire.annotations.AnnotationServiceFactory</serviceFactory>
</service>
</beans>
4 测试 http://localhost:8080/fullSearchWS/services/GeoSearch?wsdl 搞定 就这轻松几步!
总结 使用xfire做webservice很简单 支持xml配置和标注两种方式 很方便 但是 如果想把服务做好 还要好好专研一番的!
转载请注明出处: http://www.cnblogs.com/likehua/archive/2011/05/10/xfire_sample.html