记录关于WebService的简单使用

 

maven依赖

<dependency>
    <groupId>org.glassfish.main.javaee-api</groupId>
    <artifactId>javax.jws</artifactId>
    <version>3.1.2.2</version>
</dependency>
<dependency>
    <groupId>javax.xml.ws</groupId>
    <artifactId>jaxws-api</artifactId>
    <version>2.3.1</version>
</dependency>    

 

服务类

import javax.xml.ws.Endpoint;
import org.xml.sax.SAXException;
import com.alibaba.fastjson.JSON;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;

@WebService(targetNamespace = "http://service.com/")
@SOAPBinding(style = SOAPBinding.Style.RPC)
public class WebServiceH {
    
    @WebMethod(operationName = "service")
    public String service(String param) {
        return "sucess";
    }
    
    @WebMethod(exclude = true)
    public void startWebService() {
        Endpoint.publish("http://127.0.0.1:8001/webService", new WebServiceH());
        System.out.println("Server ready...");
    }
}

 

posted @ 2021-03-11 15:17  一十三  阅读(89)  评论(0)    收藏  举报