java webservice应用总结

java  webservice应用总结
 step1:在工程中导入xfire-all.jar(这是xfire需要的class包)以及对方的class包

 step2: 在工程的src/META-INF下面新建文件夹xfire,在里面添加service.xml文件
 



其中内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xfire.codehaus.org/config/1.0">
  
    <service>
        <name>LetterFeedback</name>
        <serviceClass>com.megait.xzxk.webservice.IXzxkService</serviceClass>
        <implementationClass>com.cicro.project.shfgw.ws.service.impl.LetterFeedbackService</implementationClass>
        <style>wrapped</style>
        <use>literal</use>
        <scope>application</scope>
    </service>
</beans>
以上是配置service接口以及实现类
下面是Java代码:
public class LetterFeedbackService implements IXzxkService {


    private static final Log log = LogFactory.getLog(LetterFeedbackService.class);


    // 领导信箱: model_id = 1
    // pur_id与tbmail.type映射
    public static final Map<Integer, Integer> PURID2TYPE_MAPPING = new HashMap<Integer, Integer>();


    static {
        PURID2TYPE_MAPPING.put(10, 347);
        PURID2TYPE_MAPPING.put(12, 352);
        PURID2TYPE_MAPPING.put(2, 375);
        PURID2TYPE_MAPPING.put(4, 0);
    }


    @Override
    public List<StandardInfo> createObjList() throws AhDataException {
        if (log.isInfoEnabled()) {
            log.info("Letter Feedback Service Create start...");
        }


        List<StandardInfo> list = new ArrayList<StandardInfo>();


        List<XSqBean> sqList = XSqManager.extractSqList();


        StandardInfo info = null;
        Tbmail tbmail = null;
        Integer tbmailType = null;


        if (sqList != null && !sqList.isEmpty()) {
            for (SQBean sq : sqList) {
                if (log.isInfoEnabled()) {
                    log.info("sq_id: " + sq.getSq_id());
                }


                tbmailType = PURID2TYPE_MAPPING.get(sq.getPur_id());


                tbmail = new Tbmail();
                tbmail.setId(sq.getSq_id());
                tbmail.setName(sq.getSq_realname());
                tbmail.setMail(sq.getSq_email());
                tbmail.setAdr(sq.getSq_address());
                tbmail.setTel(sq.getSq_phone());
                tbmail.setFax("");
                tbmail.setOther("");
                tbmail.setType(tbmailType != null ? tbmailType.intValue() : 0);
                tbmail.setTitle(sq.getSq_title2());
                tbmail.setContent(sq.getSq_content2());
                tbmail.setHf("");
                tbmail.setHf1("");
                tbmail.setHfqk("");


                try {
                    tbmail.setDatetime(DateUtil.getDate(sq.getSq_dtime()));
                } catch (ParseException e) {
                    if (log.isErrorEnabled()) {
                        log.error(e.toString());
                    }
                }


                tbmail.setLb("");


                info = new StandardInfo();
                info.setObjectInfo(encodeTbmail(tbmail));
                info.setTitle(tbmail.getTitle());
                info.setBusinesstype("上海发改委来信反馈");
                info.setDetail(tbmail.getContent());
                info.setBusinessresult("");


                list.add(info);


                XSqManager.updateSqExtracted(sq.getSq_id());
            }
        }


        if (log.isInfoEnabled()) {
            log.info("Create StandardInfo Size: " + list.size());
            log.info("Letter Feedback Service Create End.");
        }


        return list;
    }

然后把项目部署之后就会生成wsdl

http://www.shdrc.gov.cn/services/LetterFeedback?wsdl



这就可以看到我们生成的配置文件

然后在另一边可以直接调用我们wsdl中的方法就ok

具体的实现类如下:
public class Main {


    public static void main(String[] args) throws Exception {
        Service serviceModel = new ObjectServiceFactory().create(IXzxkService.class);
        XFire xfire = XFireFactory.newInstance().getXFire();
        XFireProxyFactory factory = new XFireProxyFactory(xfire);
        // String serviceUrl =
        // "http://192.168.137.4:1104/services/LetterFeedback";
        //String serviceUrl = "http://www.shfgw.gov.cn/services/ConsProject";
        String serviceUrl = "http://www.shdrc.gov.cn/services/LetterFeedback";
        IXzxkService xzxkService = (IXzxkService) factory.create(serviceModel, serviceUrl);


       /* StandardInfo info = new StandardInfo();


        WebXmSjjh xmSjjh = new WebXmSjjh();
        xmSjjh.setXmbm("aaaaaaaa");
        xmSjjh.setXmmc("bbbbbb");
        xmSjjh.setXmfr("cccc");
        xmSjjh.setJsnr("dddd");
        xmSjjh.setJsgm("中国一哥");
        xmSjjh.setPfsj(new Date());
        xmSjjh.setSpwh("是不是");
        xmSjjh.setXmlb("项目建议书");
        xmSjjh.setSpwj("yyyyy");
        xmSjjh.setSqh("ab活期");
        xmSjjh.setXmlx("7");


        info.setObjectInfo(encodeWebXmSjjh(xmSjjh));


        List<StandardInfo> list = new ArrayList<StandardInfo>();
        list.add(info);
*/
       // xzxkService.deliverObjList(list);
        
        List<StandardInfo> list= xzxkService.createObjList();
        
        System.out.println(list.size());
    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值