(亲测可用)Java webservice接口的发布和Axis调用webservice接口

参考的链接:https://www.oschina.net/question/2406773_2202837
https://blog.csdn.net/zivxiaowei/article/details/22198201
1.webservice接口的发布:
发布完成后,访问地址出现xml文件即发布成功

package com.xxx.ticket;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.xml.ws.Endpoint;

/**
 * @author xks
 * @date 2020/7/13 15:28
 * @description : webServece 接口的发布
 */
@WebService
public class TestWebservice {
    @WebMethod(action = "sayHello")
    public String sayHello(@WebParam(name="name") String sname){
        return "hello : " + sname;
    }

    public static void main(String[] args){
        Endpoint.publish("http://localhost:8060/TestWebservice",new TestWebservice());
    }
}

2.Axis调用webservice接口

package com.orient.tdm201.vehicleCheck.business;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;

import javax.xml.namespace.QName;

/**
 * @author xks
 * @date 2020/7/13 16:44
 * @description :
 */
public class Test {


    public static void main(String[] args) {

        try {
            String endpoint = "http://localhost:8060/TestWebservice?wsdl";
            // 直接引用远程的wsdl文件
            // 以下都是套路
            Service service = new Service();
            Call call = (Call) service.createCall();
            call.setTargetEndpointAddress(endpoint);
            // WSDL里面描述的接口名称  sayHello:方法名  http://ticket.xxx.com/:访问的xml中的 namespace
            call.setOperationName(new QName("http://ticket.xxx.com/","sayHello"));
            // name : 变量名
            call.addParameter("name",
                    org.apache.axis.encoding.XMLType.XSD_DATE,
                    javax.xml.rpc.ParameterMode.IN);// 接口的参数
            call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);// 设置返回类型

            String result = (String) call.invoke(new Object[] {"12123"});
            // 给方法传递参数,并且调用方法
            System.out.println("result is " + result);
        } catch (Exception e) {
            System.err.println(e.toString());
        }
    }
}

3.上述接口的wsdl

This XML file does not appear to have any style information associated with it. The document tree is shown below.
<!--
 Published by JAX-WS RI (http://jax-ws.java.net). RI's version is JAX-WS RI 2.2.9-b130926.1035 svn-revision#5f6196f2b90e9460065a4c2f4e30e065b245e51e. 
-->
<!--
 Generated by JAX-WS RI (http://jax-ws.java.net). RI's version is JAX-WS RI 2.2.9-b130926.1035 svn-revision#5f6196f2b90e9460065a4c2f4e30e065b245e51e. 
-->
<definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://ticket.xxx.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://ticket.xxx.com/" name="TestWebserviceService">
<types>
<xsd:schema>
<xsd:import namespace="http://ticket.xxx.com/" schemaLocation="http://localhost:8060/TestWebservice?xsd=1"/>
</xsd:schema>
</types>
<message name="sayHello">
<part name="parameters" element="tns:sayHello"/>
</message>
<message name="sayHelloResponse">
<part name="parameters" element="tns:sayHelloResponse"/>
</message>
<portType name="TestWebservice">
<operation name="sayHello">
<input wsam:Action="sayHello" message="tns:sayHello"/>
<output wsam:Action="http://ticket.xxx.com/TestWebservice/sayHelloResponse" message="tns:sayHelloResponse"/>
</operation>
</portType>
<binding name="TestWebservicePortBinding" type="tns:TestWebservice">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="sayHello">
<soap:operation soapAction="sayHello"/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="TestWebserviceService">
<port name="TestWebservicePort" binding="tns:TestWebservicePortBinding">
<soap:address location="http://localhost:8060/TestWebservice"/>
</port>
</service>
</definitions>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值