xfire发布webservice
第一步:编写xfire的服务器端
首先需要xfire的jar文件,可以到官方网站下载 ,同时根据自己项目的需要下载oracle的jar文件,springjar文件和struts的jar文件。
你可以直接访问这个地址下载:http://eft21.download.csdn.net/
然后编写web.xml文件在里面配置xfire,spring等
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
classpath:/com/stt/apps/doms/application_context.xml,
/WEB-INF/classes/pms/Application*.xml,/WEB-INF/classes/xfire.xml
org.springframework.web.context.ContextLoaderListener
在src目录下放入xfire的配置文件
customEditors.xml
xfire.xml文件
singleton="true" />
singleton="true" init-method="initialize" destroy-method="dispose">
init-method="createDefaultMappings" singleton="true">
singleton="true">
singleton="true">
singleton="true">
和xfireXmlBeans.xml文件
singleton="true">
singleton="true">
singleton="true"/>
并且在在src目录中建立META-INF目录并建立xfire目录加入services.xml文件里面配置要发布的服务的类名
com.stt.apps.doms.service.extenal.ExportFileService
com.stt.apps.doms.service.extenal.impl.ExportFileServiceImpl
然后再WEB-INF目录中加入xfireXmlBeans.xml文件配置如下:
singleton="true">
singleton="true">
singleton="true"/>
到现在为止所有的配置文件已经完成,接着我们该写对应的业务逻辑(ExportFileService)和数据逻辑(ExportFileDao)等
并配置spring的配置文件等
第二步:客户端的编写
客户端就相对简单些了,我们可以用axis技术实现
axis的客户端jar文件可以到官方网站下载
你可以直接访问这个地址下载:http://eft21.download.csdn.net/
建立两个批处理文件
1,cp.bat
内容:
set cp=%cp%;%1
2,wsdl2java.bat
内容:
set cp=
for %%1 in (E:/client/*.jar) do call cp.bat %%1
java -cp %cp% org.apache.axis.wsdl.WSDL2Java http://localhost:8080/wsdexfire/exportService?wsdl
pause
运行一下wsdl2java.bat文件可以得到客户端文件
我们可以编写简单的测试文件来调用服务 test.java:
package test;
import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RemoteException;
import org.apache.axis.AxisFault;
import com.web.service.ExportServiceHttpBindingStub;
public class Test {
public static void main(String[] args) {
URL u;
try {
u = new URL("http://localhost:8080/wsdexfire/exportService");
ExportServiceHttpBindingStub ins = new ExportServiceHttpBindingStub(u,null);
System.out.println(ins.getLoginName(71));
} catch (AxisFault e) {
e.printStackTrace();
}catch (MalformedURLException e1) {
e1.printStackTrace();
}catch (RemoteException e) {
e.printStackTrace();
}
}
}
完成!
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
