zoukankan      html  css  js  c++  java
  • axis客户端访问webservice

    1.项目环境:axis1.4

    2.pom.xml

    <!-- https://mvnrepository.com/artifact/org.apache.axis/axis -->
            <dependency>
                <groupId>org.apache.axis</groupId>
                <artifactId>axis</artifactId>
                <version>1.4</version>
            </dependency>
    
            <!-- https://mvnrepository.com/artifact/org.glassfish/javax.xml.rpc -->
            <dependency>
                <groupId>org.glassfish</groupId>
                <artifactId>javax.xml.rpc</artifactId>
                <version>3.2-b06</version>
            </dependency>
            <!-- https://mvnrepository.com/artifact/log4j/log4j -->
            <dependency>
                <groupId>log4j</groupId>
                <artifactId>log4j</artifactId>
                <version>1.2.17</version>
            </dependency><!-- https://mvnrepository.com/artifact/commons-logging/commons-logging -->
            <dependency>
                <groupId>commons-logging</groupId>
                <artifactId>commons-logging</artifactId>
                <version>1.2</version>
            </dependency>
    
            <!-- https://mvnrepository.com/artifact/commons-discovery/commons-discovery -->
            <dependency>
                <groupId>commons-discovery</groupId>
                <artifactId>commons-discovery</artifactId>
                <version>0.5</version>
            </dependency>
            <!-- https://mvnrepository.com/artifact/wsdl4j/wsdl4j -->
            <dependency>
                <groupId>wsdl4j</groupId>
                <artifactId>wsdl4j</artifactId>
                <version>1.6.3</version>
            </dependency>

    3.wsdl定义的java接口

    String hello(@WebParam(name = "text") String text);

     4.客户端代码

       /**
         * 
         * @param args
         * @throws Exception 
         */
        public static void main(String[] args) throws Exception {
            String endpoint = "http://127.0.0.1:8080/helloWorld?wsdl";
            String targetNamespace = "http://ws.sharp.com/";
            //所调用接口的方法method  
            String method = "hello";
            try {
                // 创建一个服务(service)调用(call)  
                Service service = new Service();
                Call call = (Call) service.createCall();// 通过service创建call对象  
                // 设置service所在URL  
                call.setTargetEndpointAddress(new java.net.URL(endpoint));
                call.setOperationName(new QName(targetNamespace, method));
                call.setUseSOAPAction(true);
    
                call.addParameter("text", XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
                call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);// 设置返回类型  
                String jsonString = (String) call.invoke(new Object[] { "我是测试数据" });//此处为数组,有几个变量传几个变量  
    
                System.out.println(jsonString);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    5.调用结果

    Hello 我是测试数据
  • 相关阅读:
    Java代码打成jar后 classgetClassLoadergetResource("")返回为null
    springboot-yml内list、map组合写法
    rpc-java 生成代码路径设置
    Git操作 :从一个分支cherry-pick多个commit到其他分支
    使用maven插件生成grpc所需要的Java代码
    'Failed to import pydot. You must `pip install pydot` and install graphviz
    seasonal_decompose plot figsize
    Failed to install 'TwoSampleMR' from GitHub
    prophet Building wheel for fbprophet (setup.py) ... error
    python matplotlib 绘图线条类型和颜色选择
  • 原文地址:https://www.cnblogs.com/malaya/p/9120555.html
Copyright © 2011-2022 走看看