WebService服务及客户端调用简单实例

一、服务端

package io.renren.modules.webservice.service;
import javax.jws.WebService;
import javax.xml.ws.Endpoint;

/**
 * Created by Icebery on 2017/10/11.
 */
@WebService
public class Function {
    //该方法就是要暴露给其他应用程序调用的方法

    public String transWords(String words){
        String res="";
        res=words.toUpperCase();
//        for(char ch : words.toCharArray()){
//            res+="\t"+ch+"\t";
//        }
        return res;
    }

    //这里我们使用main方法来发布我们的service
    public static void  main(String[] args){
        Endpoint.publish("http://localhost:9001/Service/Function",new Function());
        System.out.println("Publish Success~");
    }
}


二、客户端调用

package io.renren.modules.webservice.service;

/**
 * Created by Icebery on 2017/10/11.
 */
public class TestWs {
    public static void main(String[] args){
        Function fu;
        fu=new Function();
        String str=fu.transWords("I Love Lee!");
        System.out.println(str);
    }
}


你可能感兴趣的:(Java)