• Webservice学习之——即时发布与定制发布


    一、工具

            myEclipse

            tomcat  6.0 以上版本

            axis-bin-1_4.zip

    二、即时发布

           1、解压 axis-bin-1_4.zip

           2、axis-bin-1_4.zipaxis-1_4webappsaxis     把axis发布到tomcat服务器下,及拷贝到webapps目录下

               axis 为列子项目

           3、启动tomcat,访问如下即发布sucess

         

       List 就是发布的接口位置。

         5、编写java 代码,,提供方法。如下

           把HelloWs.java 文件,.java 改为.jws  即 HelloWs.jws   拷贝到tomcat 项目axis下,重启服务器。

    public class HelloWs {
       public String Welcome(String name){
          String result= "Welcome to learning WebSerice"+name;
          return result;
       }
    }

        6、访问 HelloWs.jws 如下,即SUCESS

    <?xml version="1.0" encoding="UTF-8"?>
    
    -<wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:intf="http://localhost:8080/axis/HelloWs.jws" xmlns:impl="http://localhost:8080/axis/HelloWs.jws" xmlns:apachesoap="http://xml.apache.org/xml-soap" targetNamespace="http://localhost:8080/axis/HelloWs.jws">
    
    <!--WSDL created by Apache Axis version: 1.4 Built on Apr 22, 2006 (06:55:48 PDT)-->
    
    
    
    -<wsdl:message name="WelcomeRequest">
    
    <wsdl:part name="name" type="xsd:string"/>
    
    </wsdl:message>
    
    
    -<wsdl:message name="WelcomeResponse">
    
    <wsdl:part name="WelcomeReturn" type="xsd:string"/>
    
    </wsdl:message>
    
    
    -<wsdl:portType name="HelloWs">
    
    
    -<wsdl:operation name="Welcome" parameterOrder="name">
    
    <wsdl:input name="WelcomeRequest" message="impl:WelcomeRequest"/>
    
    <wsdl:output name="WelcomeResponse" message="impl:WelcomeResponse"/>
    
    </wsdl:operation>
    
    </wsdl:portType>
    
    
    -<wsdl:binding name="HelloWsSoapBinding" type="impl:HelloWs">
    
    <wsdlsoap:binding transport="http://schemas.xmlsoap.org/soap/http" style="rpc"/>
    
    
    -<wsdl:operation name="Welcome">
    
    <wsdlsoap:operation soapAction=""/>
    
    
    -<wsdl:input name="WelcomeRequest">
    
    <wsdlsoap:body use="encoded" namespace="http://DefaultNamespace" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
    
    </wsdl:input>
    
    
    -<wsdl:output name="WelcomeResponse">
    
    <wsdlsoap:body use="encoded" namespace="http://localhost:8080/axis/HelloWs.jws" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
    
    </wsdl:output>
    
    </wsdl:operation>
    
    </wsdl:binding>
    
    
    -<wsdl:service name="HelloWsService">
    
    
    -<wsdl:port name="HelloWs" binding="impl:HelloWsSoapBinding">
    
    <wsdlsoap:address location="http://localhost:8080/axis/HelloWs.jws"/>
    
    </wsdl:port>
    
    </wsdl:service>
    
    </wsdl:definitions>
    wsdl文件代码

      测试代码:

    public static void main(String[] args) {
            //请求地址
            String  url="http://localhost:8080/axis/HelloWs.jws";
           //、创建服务    
            Service service =new Service();
            try {
                //调用服务
                Call call=(Call) service.createCall();
                //服务地址
                call.setTargetEndpointAddress(url);
                //请求方法
                call.setOperationName(new QName(url,"Welcome"));
                //执行调用
                String result=(String) call.invoke(new Object[]{"  Mrwanggang"});
                System.out.println(result);
            } catch (ServiceException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (RemoteException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
    
        }
    View Code

    即时发布完成

    二、定制发布(WSDD)

      1、编写java代码,,即要发布的方法。

          

     public String Wel(String name){
            return "欢迎您: "+name;
         } 

     2、把编译后的文件(带包路径)拷贝到 (本地服务器)apache-tomcat-7.0.42webappsaxisWEB-INFclasses下

    3、修改server-config.wsdd文件 (server-config.wsdd  据了解这个文件需要先写自己的.wsdd文件,然后在Axisweb-inf下执行命令生成的)

          java  org.apache.axis.client.AdminClient*.wsdd  生成的。

        写自己的.wsdd文件参照如下文件deploy.wsdd

       

       重点关注

         <!--配置服务接口-->
         <service name="HelloWsdd" provider="java:RPC"> <!-- HelloWsdd 接口名称 --> 
                <parameter name="className" value="com.wg.wsdd.HelloWsdd"/>   <!--接口文件位置--> 
                <parameter name="allowedMethods" value="*"/>   <!--* 代表所有方法,也可单个指明,发布的方法-->
         </service>
    <?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.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="URLMapper" type="java:org.apache.axis.handlers.http.URLMapper"/> 
         <handler name="Authenticate" type="java:org.apache.axis.handlers.SimpleAuthenticationHandler"/>   
         <!--配置服务接口-->
         <service name="HelloWsdd" provider="java:RPC">
                <parameter name="className" value="com.wg.wsdd.HelloWsdd"/>    
                <parameter name="allowedMethods" value="*"/>   <!--* 代表所有方法,也可单个指明
                <beanMapping languageSpecificType="java:anni.Order" qname="ns1:Order" xmlns:ns1="BeanService"/>-->
           </service>
    
         
         <transport name="http">  
             <requestFlow>   
                 <handler type="URLMapper"/>   
                 <handler type="java:org.apache.axis.handlers.http.HTTPAuthHandler"/>  
             </requestFlow> 
         </transport> 
         <transport name="local">  
             <responseFlow>   
                 <handler type="LocalResponder"/>  
             </responseFlow> 
         </transport>
    </deployment>
    View Code

     3、拷贝  server-config.wsdd  到——>apache-tomcat-7.0.42webappsaxisWEB-INF 下即可。

     4、重新启动服务器,访问 http://localhost:8080/axis/   点击 List  如下即是你发布的位置

     5、测试代码

     */
        public static void main(String[] args) {
            //请求地址
            String  url="http://localhost:8080/axis/services/HelloWsdd";
           //、创建服务    
            Service service =new Service();
            try {
                //调用服务
                Call call=(Call) service.createCall();
                //服务地址
                call.setTargetEndpointAddress(url);
                //请求方法
                call.setOperationName(new QName(url,"Wel"));
                //执行调用
                String result=(String) call.invoke(new Object[]{"Mrwangg"});
                System.out.println(result);
            } catch (ServiceException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (RemoteException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
    
        }
    View Code

                                        定制发布完成

  • 相关阅读:
    python第八课
    python第七课
    python第六课
    python第五课
    Python基础30类-内置函数实现迭代器协议
    Python基础29类-内置函数(__format__,__slots__,__doc__,__module__,__del__,__call__)
    Python基础28类-内置函数(__getattribute__,__getitem__,__setitem__.__delittem__)
    Python基础27类-包装、组合方式授权、判断对象类型的方法
    Python基础26类-内置函数__setattr__,__getattr__,__delattr__
    Python基础25类-反射
  • 原文地址:https://www.cnblogs.com/aGboke/p/6235083.html
Copyright © 2020-2023  润新知