webservice demo

#webservice Starting examples
#### Note: This post is for learning memorandum using idea + win10 development (not related)

1. The first step is to create a new webservice project.
Click the menu file-> new- > project to
Write a picture description here
hook the webservice. The other parts should be as consistent as possible in this article. Then click next and enter the project name (enter the specifications at will)

2. Create a new package directory and two classes
Write a picture description here
with attached codes (the code is recommended to be handwritten and pay attention to package references):

package com.webservice.service;

import javax.jws.WebService;

/**
 * Created by yangchao on 2017/2/13.
 */
@WebService
public class Service {

    public String getService(){
        return "Hello Word";
    }

    public String getName(){
        return "Scholar";
    }
}

package com.webservice.service;

import javax.xml.ws.Endpoint;

/**
 * Created by yangchao on 2017/2/13.
 */
public class TestService {
    public static void main(String[] args) {
/* 确定端口 + 路径没用被占用 */      Endpoint.publish("http://127.0.0.1:8088/web/myservice", new Service());
        System.out.println("初始成功");
    }
}

3. Run the main method of TestService.java The
console reports no errors and prints out
Write a picture description here
. Go to the next step to open the web page: http://127.0.0.1:8088/web/myservice
See the following content that the server has been successfully built
Write a picture description here

4. Use the wsimport command to generate the client (open the dos window or execute the dos command with the idea terminal window)
wsimport -s D: / java_ide / web_service / src -p com.webservice.client.service -keep http: //127.0 .0.1: 8088 / web / myservice? Wsdl
wsimport -s (project src path) -p (the generated code storage directory) -keep (the WSDL address in the screenshot above is not the interface address bound by the webservice)

5. New class
TestClient.java code is as follows

package com.webservice.client;

import com.webservice.client.service.Service;
import com.webservice.client.service.ServiceService;

/**
 * Created by yangchao on 2017/2/13.
 */
public class TestCline {
    public static void main(String[] args) {
        Service service = new ServiceService().getServicePort();
        System.out.println(service.getService());
        System.out.println("my name is :" + service.getName());
    }
}

Run to get the result:
Write a picture description here

Beginner tutorial ends

Published 17 original articles · won 24 · views 280,000 +

Guess you like

Origin blog.csdn.net/qq_22956867/article/details/55051139