Java快速生成一个简单的webservice服务端

本文讲解如何快速发布一个简单的webservice服务端,在实际工作中一般会使用cxf、axis等框架来实现

一、编写Java代码

package com.wsdl.services;

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

/**
 * @author administrator
 * @date 2020-06-09 22:02
 */
@WebService
public class HelloWorld {

    @WebMethod
    public String sayHello(String str) {
        String result = "Hello World " + str;
        return result;
    }

    public static void main(String[] args) {
        String wsdlAddress = "http://127.0.0.1:8001/HelloWorld";
        HelloWorld implementor = new HelloWorld();
        Endpoint.publish(wsdlAddress, implementor);
        System.out.println("server is running");
    }

}

二、运行结果

http://127.0.0.1:8001/HelloWorld?wsdl
在这里插入图片描述

三、测试结果

需要提前安装好SoapUI工具,本文使用SoapUI工具验证服务

  • 测试请求报文
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://services.wsdl.com/">
   <soapenv:Header/>
   <soapenv:Body>
      <ser:sayHello>
         <!--Optional:-->
         <arg0><![CDATA[张三丰 ]]></arg0>
      </ser:sayHello>
   </soapenv:Body>
</soapenv:Envelope>

在这里插入图片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章