使用weblogic11g+XFire发布web service服务

1、问题:

    原来使用axis2+spring在tomcat中发布web service服务,最近系统优化升级中间件为weblogic11g以后,axis2+spring发布的服务在调用后返回的soap内容与优化升级前的格式不一致。

 

老的tomcat服务器返回的信息的格式:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">

   <soapenv:Body>

      <ns:savePayBillResponse xmlns:ns="http://paybill.server.webservice.marion.com/xsd">

         <ns:return>

            <accountYear xmlns="http://bean.server.webservice.marion.com/xsd">2011</accountYear>

            <accountingDocNo xmlns="http://bean.server.webservice.marion.com/xsd">1500000483</accountingDocNo>

            <billNo xmlns="http://bean.server.webservice.marion.com/xsd">111103000000</billNo>

            <corpCode xmlns="http://bean.server.webservice.marion.com/xsd">1001</corpCode>

            <returnCode xmlns="hthttp://bean.server.webservice.marion.com/xsd">01</returnCode>

            <returnMsg xmlns="http://bean.server.webservice.marion.com/xsd">导入成功!</returnMsg>

         </ns:return>

      </ns:savePayBillResponse>

   </soapenv:Body>

</soapenv:Envelope>

 

新的weblogic服务器返回的信息的格式:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">

   <soapenv:Body>

      <ns:savePayBillResponse xmlns:ns="http://paybill.server.webservice.marion.com/xsd">

         <ns:return>

            <accountYear xmlns="http://bean.server.webservice.marion.com/xsd">2011</accountYear>

            <accountingDocNo>1500000483</accountingDocNo>

            <billNo>111103000000</billNo>

            <corpCode>1001</corpCode>

            <returnCode>01</returnCode>

            <returnMsg>导入成功!</returnMsg>

         </ns:return>

      </ns:savePayBillResponse>

   </soapenv:Body>

</soapenv:Envelope>

可以看出namespace的定义部分在优化后不见了。

由于笔者比较笨,只能采用换web service框架的方法。决定采用XFire试试。

 

2、调查:

    在网上搜了下,各种用XFire发布web serivce的方法还真不少,但笔者试了典型的两个都以失败告终。由于原系统是采用axis2+spring的思路,所以笔者自然而然的认为XFire也必须配合spring来完成发布web service服务的任务,至少要手动导入一个spring.jar,有一个applicationContext.xml配置文件等等。网上介绍的各种配置方法也都假模假样的在web.xml里配置spring的listener,配置XFire与spring关联的各种类,在applicationContext.xml中配置bean等等。不能说不复杂。

 

3、解决:

(1)、环境

    由于试了两个网上的方案都失败了,恼火之下,笔者直接在MyEclipse6.0中新建webservice project,MyEclipse自动为新的web service project引入XFire 1.2 Core Libraries,MyEclipse自动在与WebRoot同级的目录下新建一个WebService文件夹,内含一个services.xml文件,同时WebRoot中的web.xml也已经自动写入了对XFire的加载相关配置,真爽,笔者决定直接开弄,其他什么余外的包都不引入。

(2)、编码与配置

a、 src文件夹的目录如下

   src

       com.marion.test

                  Test.java

                  InputParameter.java

                  OutputResult.java

 说明:Test类是服务类,里面有一个方法public OutputResult doSomeThing(InputParameter){.....},方法内主要内容是硬编码返回一个固定的OutputResult对象。

b、 service.xml的配置:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xfire.codehaus.org/config/1.0">  
  <service>
    <name>PaybillService</name>
    <serviceClass>com.marion.test.Test</serviceClass>
  </service>
</beans>

看到了没有?完全看不到关于spring的任何配置(虽然在XFire 1.2 Core Libraries中包含了spring-1.2.6.jar),你所做的只是写一个服务类的path,给服务起个名字,就这么简单。

在weblogic11g中发布服务以后,wsdl地址是:

http://localhost:7001/xfiretest/services/PaybillService?wsdl,其中xfiretest是我的工程名。

使用soapUI尝试访问服务,得到的返回结果的大概结构是:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soap:Body>
      <ns1:doSomeThingResponse xmlns:ns1="http://Test.test.marion.com/">
         <ns1:out>
            <accountYear xmlns="http://Test.test.marion.com/"> 2011</accountYear>          

            <accountingDocNo xmlns="http://Test.test.marion.com/">aaa</accountingDocNo>

            <billNo xmlns="http://Test.test.marion.com/">123</billNo>
            <corpCode xmlns="http://Test.test.marion.com/">code</corpCode>

            <returnCode xmlns="http://Test.test.marion.com/">returncode</returnCode>

            <returnMsg xmlns="http://Test.test.marion.com/">returnMsg</returnMsg>

         </ns1:out>
      </ns1:doSomeThingResponse>
   </soap:Body>
</soap:Envelope>

搞定!

PS:后来通过修改应用中的weblogic.xml文件,添加

 

<container-descriptor>
<prefer-web-inf-classes>true</prefer-web-inf-classes>
</container-descriptor>

 

这样不需要换成XFire,使用原axis2也解决了问题。

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值