Web Service 入门

在网上招聘看到有些要会 web service ,发现网上这方面的教程好少,学了一下,学的迷迷糊糊的,也不知道为什么要这样做,这样做有什么用。
不管了还行写下笔记,万一以后会用到呢。

准备

创建一个java项目,普通web都行,这里使用的是maven创建的
导入pom

<dependency>
    <groupId>org.apache.axis</groupId>
    <artifactId>axis</artifactId>
    <version>1.4</version>
</dependency>

<dependency>
    <groupId>commons-logging</groupId>
    <artifactId>commons-logging</artifactId>
    <version>1.2</version>
</dependency>

<dependency>
    <groupId>commons-discovery</groupId>
    <artifactId>commons-discovery</artifactId>
    <version>0.5</version>
</dependency>

<dependency>
    <groupId>org.apache.axis</groupId>
    <artifactId>axis-jaxrpc</artifactId>
    <version>1.4</version>
</dependency>

<dependency>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>1.2.17</version>
</dependency>


<dependency>
    <groupId>javax.xml.soap</groupId>
    <artifactId>saaj-api</artifactId>
    <version>1.3.4</version>
</dependency>

<dependency>
    <groupId>wsdl4j</groupId>
    <artifactId>wsdl4j</artifactId>
    <version>1.6.3</version>
</dependency>

webService:获取城市天气情况的程序

学习于:JAVA:一个程序学会用webService

  1. 点击java文件夹
    在这里插入图片描述

使用

public class Main {
    public static void main(String[] args) throws Exception {
        //建立 第一个接口实例类
        WeatherWebServiceLocator sevice = new WeatherWebServiceLocator();
        WeatherWebServiceSoap_PortType portType = sevice.getWeatherWebServiceSoap();
        String[] citys = portType.getWeatherbyCityName("广安");

        for (String city : citys) {
            System.out.println(city);
        }

    }
}

效果

在这里插入图片描述

自己建立

@WebService
public class Function {
     String name;
    public String transWords(String words){

        String res = "";
        for(char ch : words.toCharArray()){
            res += ch+",";
        }
        return res;
    }

    public static void main(String[] args) {
        // 使用Endpoint(终端)类发布webservice
        Function function = new Function();
       function.name = "展示";

        Endpoint.publish("http://localhost:8089/service/function", function);
        System.out.println("Publish Success");
//        http://localhost:8089/service/function?wsdl
    }
}

访问地址 http://localhost:8089/service/function?wsdl
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值