新书推介:《语义网技术体系》
作者:瞿裕忠,胡伟,程龚
   XML论坛     W3CHINA.ORG讨论区     计算机科学论坛     SOAChina论坛     Blog     开放翻译计划     新浪微博  
 
  • 首页
  • 登录
  • 注册
  • 软件下载
  • 资料下载
  • 核心成员
  • 帮助
  •   Add to Google

    >> Web服务(Web Services,WS), 语义Web服务(Semantic Web Services, SWS)讨论区: WSDL, SOAP, UDDI, DAML-S, OWL-S, SWSF, SWSL, WSMO, WSML,BPEL, BPEL4WS, WSFL, WS-*,REST, PSL, Pi-calculus(Pi演算), Petri-net,WSRF,
    [返回] 计算机科学论坛W3CHINA.ORG讨论区 - Web新技术讨论『 Web Services & Semantic Web Services 』 → 转贴:用axis开发webservice实践 查看新帖用户列表

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 3697 个阅读者浏览上一篇主题  刷新本主题   树形显示贴子 浏览下一篇主题
     * 贴子主题: 转贴:用axis开发webservice实践 举报  打印  推荐  IE收藏夹 
       本主题类别:     
     titanbai 帅哥哟,离线,有人找我吗?
      
      
      等级:大一新生
      文章:5
      积分:91
      门派:XML.ORG.CN
      注册:2006/7/14

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给titanbai发送一个短消息 把titanbai加入好友 查看titanbai的个人资料 搜索titanbai在『 Web Services & Semantic Web Services 』的所有贴子 引用回复这个贴子 回复这个贴子 查看titanbai的博客楼主
    发贴心情 转贴:用axis开发webservice实践

    【摘 要】Axis本质上就是一个SOAP引擎,提供创建服务器端、客户端和网关SOAP操作的基本框架。Axis目前版本是为Java编写的,不过为C++的版本正在开发中。
      
      什么是SOAP?

      SOAP是一个基于XML的用于应用程序之间通信数据编码的传输协议。最初由微软和Userland Software提出,随着不断地完善和改进,SOAP很快被业界广泛应用。

      什么是Axis?

      Axis本质上就是一个SOAP引擎,提供创建服务器端、客户端和网关SOAP操作的基本框架。Axis目前版本是为Java编写的,不过为C++的版本正在开发中。

      配置webservice具体步骤:

      1.安装weblogic。

      2.配置一个web应用,如“\\lijunjie\e$\software\bea\user_projects\domains\lijjdomain\applications\ cntapws “。

      3.从apache网站上下载axis-bin-1_2_1.tar.gz,解压后copy到cntapws下面。

      4.打开“http://localhost:7001/console“,配置cntapws 的web应用。

      5.axis1.2和weblogic8.1有冲突,原因是weblogic 本身携带的webservice.jar使用的旧的javax.xml.soap.*,而不是像axis使用J2EE1.4新的版本。解决方案是在WEB -INF/weblogic.xml文件中如下的配置:

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


      6.按 http://localhost:8080/axis/happyaxis.jsp地址,可以显示你发布的webservice是否配置成功,如果显示必须的包缺失,则你的webservice不能正常运行。

      开发webservice流程

      1.写普通的java类,该类中有你要发布到webservice上的有关方法。

      2.配置server-comfig.xml, 把你要发布的方法写入该文件。具体内容如下:

    <?xml version="1.0" encoding="UTF-8"?>

    <deployment xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">

    <globalConfiguration>

    <parameter name="adminPassword" value="admin"/>

    <parameter name="attachments.Directory" value="C:\eclipse\workspace\bookstore\WEB-INF\attachments"/>

    <parameter name="attachments.implementation" value="org.apache.axis.attachments.AttachmentsImpl"/>

    <parameter name="sendXsiTypes" value="true"/>

    <parameter name="sendMultiRefs" value="true"/>

    <parameter name="sendXMLDeclaration" value="true"/>

    <parameter name="axis.sendMinimizedElements" value="true"/>

    <requestFlow>

    <handler type="java:org.apache.axis.handlers.JWSHandler">

    <parameter name="scope" value="session"/>

    </handler>

    <handler type="java:org.apache.axis.handlers.JWSHandler">

    <parameter name="scope" value="request"/>

    <parameter name="extension" value=".jwr"/>

    </handler>

    </requestFlow>

    </globalConfiguration>

    <handler name="LocalResponder" type="java:org.apache.axis.transport.local.LocalResponder"/>

    <handler name="Authenticate" type="java:org.apache.axis.handlers.SimpleAuthenticationHandler"/>

    <handler name="URLMapper" type="java:org.apache.axis.handlers.http.URLMapper"/>

    <service name="Version" provider="java:RPC">

    <parameter name="allowedMethods" value="getVersion"/>

    <parameter name="className" value="org.apache.axis.Version"/>

    </service>

    <!--要配置的内容start,注意每一个要发布成webservice的类都要配置成一个service如下à

    <service name="webserviceproxy" provider="java:RPC">

    <parameter name="className" value="com.copia.webservice.server.proxy.WebServiceProxy"/>

    <parameter name="allowedMethods" value="*"/>

    <!—具体某个方法说明-->

    <operation name="login" returnType="ns:LoginOutServiceBean">

    <parameter name="branchNo" type="xsd:string"/>

    <parameter name="userId" type="xsd:string"/>

    <parameter name="password" type="xsd:string"/>

    <parameter name="certificateNo" type="xsd:string"/>

    </operation>

    <!—如果该方法的参数有基本类型和对象类型,则不要声明,webservice能够找到相关的类及方法-->

    <!—声明涉及到的所有类及其父类,引用类,还有它们的相关类,类似与对象树遍历,某个类声明缺失也会导致运行失败-->

    <typeMapping deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory"

    encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"

    qname="ns:LoginOutServiceBean"

    serializer="org.apache.axis.encoding.ser.BeanSerializerFactory"

    type="java:com.copia.core.module.security.login.LoginOutServiceBean" xmlns:ns="webserviceproxy"/>

    <typeMapping deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory"

    encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"

    qname="ns:User"

    serializer="org.apache.axis.encoding.ser.BeanSerializerFactory"

    type="java:com.copia.core.client.User" xmlns:ns="webserviceproxy"/>

    <typeMapping deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory"

    encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"

    qname="ns:GetBatchListInServiceBean"

    serializer="org.apache.axis.encoding.ser.BeanSerializerFactory"

    type="java:com.copia.core.module.batch.service.GetBatchListInServiceBean" xmlns:ns="webserviceproxy"/>

    <typeMapping deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory"

    encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"

    qname="ns:GetBatchListOutServiceBean"

    serializer="org.apache.axis.encoding.ser.BeanSerializerFactory"

    type="java:com.copia.core.module.batch.service.GetBatchListOutServiceBean" xmlns:ns="webserviceproxy"/>

    <typeMapping deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory"

    encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"

    qname="ns:BatchJobDefBean"

    serializer="org.apache.axis.encoding.ser.BeanSerializerFactory"

    type="java:com.copia.core.module.batch.service.BatchJobDefBean" xmlns:ns="webserviceproxy"/>

    <typeMapping deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory"

    encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"

    qname="ns:ValueObjectPage"

    serializer="org.apache.axis.encoding.ser.BeanSerializerFactory"

    type="java:com.copia.core.voa.ValueObjectPage" xmlns:ns="webserviceproxy"/>

    <typeMapping deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory"

    encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"

    qname="ns:ValueObjectColInfo"

    serializer="org.apache.axis.encoding.ser.BeanSerializerFactory"

    type="java:com.copia.core.voa.ValueObjectColInfo" xmlns:ns="webserviceproxy"/>

    <typeMapping deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory"

    encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"

    qname="ns:ValueObjectList"

    serializer="org.apache.axis.encoding.ser.BeanSerializerFactory"

    type="java:com.copia.core.voa.ValueObjectList" xmlns:ns="webserviceproxy"/>

    <typeMapping deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory"

    encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"

    qname="ns:PageInfo"

    serializer="org.apache.axis.encoding.ser.BeanSerializerFactory"

    type="java:com.copia.core.voa.PageInfo" xmlns:ns="webserviceproxy"/>

    <typeMapping deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory"

    encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"

    qname="ns:ValueObjectMetaData"

    serializer="org.apache.axis.encoding.ser.BeanSerializerFactory"

    type="java:com.copia.core.voa.ValueObjectMetaData" xmlns:ns="webserviceproxy"/>

    </service>

    <!--要配置的内容endà

    <service name="AdminService" provider="java:MSG">

    <parameter name="allowedMethods" value="AdminService"/>

    <parameter name="enableRemoteAdmin" value="false"/>

    <parameter name="className" value="org.apache.axis.utils.Admin"/>

    <namespace>http://xml.apache.org/axis/wsdd/</namespace>

    </service>

    <transport name="local">

    <responseFlow>

    <handler type="LocalResponder"/>

    </responseFlow>

    </transport>

    <transport name="http">

    <requestFlow>

    <handler type="URLMapper"/>

    <handler type="java:org.apache.axis.handlers.http.HTTPAuthHandler"/>

    </requestFlow>

    </transport>

    </deployment>

      3.在地址栏输入http://localhost:7001/cntapws/services/webserviceproxy?wsdl,如没有什么错误,则表示你的webservice发布成功了。

      Java webservice客户端编程

      1.启动你配置好的weblobic。

      2.进入dos界面,在你的临时目录(任意目录)下根据wsdl产生客户文件,如下指令:

    E:\kk>java -Djava.ext.dirs=E:\software\bea\user_projects\domains\lijjdomain\appl

    ications\axis\WEB-INF\axislib org.apache.axis.wsdl.WSDL2Java http://localhost:7001/cntapws/services/webserviceproxy?wsdl即可在kk目录下产生有关文件。

      3.把产生的文件copy到你的工程中,再写一个webservice调用测试类,如下:

    public class TestWs {

    public static void main(String[] args) {

    WebServiceProxyService service = new WebServiceProxyServiceLocator();

    try {

    WebServiceProxy serviceProxy = service.getwebserviceproxy();

    User user = new User();

    user.setBranchNo("000001");

    user.setClerkNo("1004");

    GetBatchListInServiceBean in = new GetBatchListInServiceBean();

    in.setCurPageNo(1);

    String serviceName = "GetBatchListService";

    GetBatchListOutServiceBean out = (GetBatchListOutServiceBean)serviceProxy.getBatchListService(user, in, serviceName);

    BatchJobDefBean[] defBeans = out.getBatchJobDefBeans();

    for(int i = 0 ; i < defBeans.length ; i++){

    System.out.println(defBeans[i].getBatchName());

    }

    }catch(Exception ex){

    ex.printStackTrace();

    }

    }

    }


       收藏   分享  
    顶(0)
      




    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2006/7/18 8:28:00
     
     oicq我爱玩 帅哥哟,离线,有人找我吗?
      
      
      等级:大一(猛啃高等数学)
      文章:18
      积分:150
      门派:XML.ORG.CN
      注册:2006/7/25

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给oicq我爱玩发送一个短消息 把oicq我爱玩加入好友 查看oicq我爱玩的个人资料 搜索oicq我爱玩在『 Web Services & Semantic Web Services 』的所有贴子 引用回复这个贴子 回复这个贴子 查看oicq我爱玩的博客2
    发贴心情 
    有点晕~似乎很不错。。。努力!
    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2006/7/25 19:12:00
     
     GoogleAdSense
      
      
      等级:大一新生
      文章:1
      积分:50
      门派:无门无派
      院校:未填写
      注册:2007-01-01
    给Google AdSense发送一个短消息 把Google AdSense加入好友 查看Google AdSense的个人资料 搜索Google AdSense在『 Web Services & Semantic Web Services 』的所有贴子 访问Google AdSense的主页 引用回复这个贴子 回复这个贴子 查看Google AdSense的博客广告
    2025/2/20 3:19:01

    本主题贴数2,分页: [1]

    管理选项修改tag | 锁定 | 解锁 | 提升 | 删除 | 移动 | 固顶 | 总固顶 | 奖励 | 惩罚 | 发布公告
    W3C Contributing Supporter! W 3 C h i n a ( since 2003 ) 旗 下 站 点
    苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
    6,669.922ms