使用jdk 建立web service

來源:互聯網
上載者:User

標籤:使用jdk 建立web service

1)伺服器端開發
        說明:jdk為1.7版本
            i.建立項目
                項目名稱:webs1
            ii.建立SEI(終端)
                a.包名:cn.jbit.webs1.sei
                b.介面設計
                    介面名:HelloSEI.java
                    介面內容:
                    @WebService
                    public interface HelloSEI {
                        @WebMethod
                        public String sayHello(String name);
                    }
                c.實作類別設計
                    實作類別名:HelloSEIImpl.java
                    實作類別內容:
                    @WebService
                    public class HelloSEIImpl implements HelloSEI {
                        @Override
                        public String sayHello(String name) {
                            System.out.println("sayhello");
                            return "hello"+name;
                        }
                    }
            iii.發布服務
                a.包名:cn.jbit.webs1.sei.test
                b.發布
                    類名:HelloSEITest.java
                    類內容:
                    public class HelloSEITest {
                        public static void main(String[] args) {
                            String address = "http://192.168.8.116:8989/webs1/hello";
                            Endpoint.publish(address, new HelloSEIImpl());
                            System.out.println("發布");
                        }
                    }
        2)用戶端開發
            i.建立項目
                項目名稱:wsclient
            ii.使用jdk提供的wsimport.exe產生用戶端代碼
                wsimport -target 2.0 -keep http://192.168.8.116:8989/webs1/hello?wsdl
            iii.調用服務
                a.包名:cn.jbit.webs1.sei.client
                b.調用
                    類名:ClientTest.java
                    類內容:
                    public class ClientTest {
                        public static void main(String[] args) {
                            HelloSEIImplService helloSEIImplService = new HelloSEIImplService();
                            HelloSEIImpl helloSEIImpl = helloSEIImplService.getHelloSEIImplPort();
                            String result = helloSEIImpl.sayHello("xiaoxiao");
                            System.out.println(result);
                        }
                    }

本文出自 “素顏” 部落格,請務必保留此出處http://suyanzhu.blog.51cto.com/8050189/1564064

使用jdk 建立web service

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.