xfire的webservice示例

1、首先将xfire需要的jar包上传的项目中。
[img]http://dl2.iteye.com/upload/attachment/0115/4354/c1244ea9-c7d4-3407-9a53-0208aaffe2df.png[/img]

项目的结构图:
[img]http://dl2.iteye.com/upload/attachment/0115/4359/36e86319-21de-3a9b-95c8-95368eea76d8.png[/img]

2、在web.xml文件中配置xfire信息


xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">


XFireServlet

org.codehaus.xfire.transport.http.XFireConfigurableServlet



XFireServlet
/servlet/XFireServlet/*


XFireServlet
/services/*



com.fysh.listener.PropListener




代码中配置了一个监听器,我使用监听器加载jdbc的信息保存在内存中。
3、定义接口并实现

package com.fysh.service;

public interface FyshService {

/**
* 门诊审核信息
* @param xml_mz_ycxx
* @return
*/
public String upload_mz_ycxx(String xml_mz_ycxx);

/**
* 住院审核信息
* @param xml_zy_ycxx
* @return
*/
public String upload_zy_ycxx(String xml_zy_ycxx);

/**
* 门诊信息反馈
* @param xml_mz_ycxx
* @return
*/
public String download_mz_ycxx(String xml_mz_ycxx);

/**
* 住院信息反馈
* @param xml_zy_ycxx
* @return
*/
public String download_zy_ycxx(String xml_zy_ycxx);


/**
* 阀值信息
* @param xml_mz_fzxx
* @return
*/
public String download_fzxx(String xml_fzxx);

}

接口的实现类

package com.fysh.service.impl;

import java.util.Map;

import com.fysh.dao.FyshDao;
import com.fysh.service.FyshService;

public class FyshServiceImpl implements FyshService {



/**
* 获取门诊审核反馈信息
*/
public String download_mz_ycxx(String xml_mz_ycxx) {
String resXml="";
FyshDao dao = new FyshDao();
Map resMap = dao.getMzYcxx(xml_mz_ycxx);
for (String key : resMap.keySet()) {
resXml = resXml +"<"+key+">"+resMap.get(key)+"";
}
resXml = resXml + "
";
return resXml.toLowerCase();
}

/**
* 获取住院审核反馈信息
*/
public String download_zy_ycxx(String xml_zy_ycxx) {
String resXml="";
FyshDao dao = new FyshDao();
Map resMap = dao.getZyYcxx(xml_zy_ycxx);
for (String key : resMap.keySet()) {
resXml = resXml +"<"+key+">"+resMap.get(key)+"";
}
resXml = resXml + "
";
return resXml.toLowerCase();
}

/**
* 提交门诊审核信息
*/
public String upload_mz_ycxx(String xml_mz_ycxx) {
String resXml="";
FyshDao dao = new FyshDao();
boolean resFlag = dao.saveMzYcxx(xml_mz_ycxx);
resXml = resXml+resFlag +"
";
return resXml.toLowerCase();
}

/**
* 提交住院审核信息
*/
public String upload_zy_ycxx(String xml_zy_ycxx) {
String resXml="";
FyshDao dao = new FyshDao();
boolean resFlag = dao.saveMzYcxx(xml_zy_ycxx);
resXml = resXml+resFlag +"
";
return resXml.toLowerCase();
}

/**
* 获取阀值信息
*/
public String download_fzxx(String xml_fzxx) {
String resXml="";
FyshDao dao = new FyshDao();
Map resMap = dao.getFzxx(xml_fzxx);
for (String key : resMap.keySet()) {
resXml = resXml +"<"+key+">"+resMap.get(key)+"";
}
resXml = resXml+"
";
return resXml.toLowerCase();
}

}


4、调用的类

XFireProxyFactory factory = new XFireProxyFactory(XFireFactory.newInstance().getXFire());
Client client = new Client(new URL("http://localhost:8080/fysh_webservice/services/fysh?wsdl"),FyshService.class);
String xml_zy_fk="31011411734534532";
System.out.println(((FyshService)factory.create(client)).download_zy_ycxx(xml_zy_fk));

你可能感兴趣的:(Java,Web技术分析)