日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 综合教程 >内容正文

综合教程

通过CFX发布WebService(一)

發(fā)布時(shí)間:2023/12/15 综合教程 42 生活家
生活随笔 收集整理的這篇文章主要介紹了 通过CFX发布WebService(一) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

發(fā)布WebService的方法很多。如XFire,CFX等。現(xiàn)在首先介紹下怎樣通過CFX來發(fā)部一個(gè)WebService。

(1) 首先,是從Apache官方網(wǎng)站獲取CFX的Java包。其地址是:http://cxf.apache.org/download.html。在該網(wǎng)頁上可以下載最新的CFX 的Java開發(fā)包。

(2) 其次,新建一個(gè)簡單的java工程,不必是web工程,只是通過eclipse或者myeclipse新建一個(gè)java project。將CFX的java開發(fā)包復(fù)制到該工程的classpath目錄下。

當(dāng)新建的是一個(gè)web工程時(shí),只需要將該工程復(fù)制到lib文件夾中。

(3) 在該工程中新建一個(gè)普通的接口。

package com.example.webservice;
import javax.jws.WebParam; import javax.jws.WebService; @WebService public interface HelloWorldService { public String sayHello(@WebParam(name="userName")String userName); }

注意到:上面的接口中有一個(gè)注解:@WebService,該注解表示這個(gè)是一個(gè)WebService服務(wù)

(4) 同時(shí)新建一個(gè)類,HelloWorldServiceImpl實(shí)現(xiàn)該接口。

package com.example.webservice;
import javax.jws.WebMethod; import javax.jws.WebService; @WebService(endpointInterface="com.example.webservice.HelloWorldService", serviceName="helloWorldService") public class HelloWorldServiceImpl implements HelloWorldService { @WebMethod public String sayHello(String userName) { System.out.println("HelloWorldServiceImp.sayHello("+userName+")"); return "Hello,"+userName; } }

注意:這個(gè)實(shí)現(xiàn)類中,也有注解,一個(gè)是@WebService注解,該注解中有2個(gè)部分,一個(gè)是endpointInterface="com.example.webservice.HelloWorldService",

這里的內(nèi)容是上面的接口的完整包名和接口名組成的。另一個(gè)是serviceName="helloWorldService",這個(gè)是用來現(xiàn)實(shí)該webService的入口的,即該webservice的名稱為

helloWorldService。當(dāng)調(diào)用該webservice時(shí),其地址應(yīng)該是:htt://IpAddress:port/helloWorldService

還有另一個(gè)注解:@WebMethod,該注解用來標(biāo)識了webService的實(shí)現(xiàn)方法。

現(xiàn)在主要的webservice的功能已經(jīng)實(shí)現(xiàn)了,所要做的是將webservice進(jìn)行發(fā)布。發(fā)布該webservice的方法有好幾種,可以用Spring發(fā)布,也可以直接運(yùn)行一個(gè)main還是發(fā)布。

現(xiàn)在演示的是用一個(gè)main函數(shù)發(fā)布該webservice。

新建一個(gè)類,該類中有一個(gè)main函數(shù)。

import javax.xml.ws.Endpoint;

import com.lenovo.webservice.HelloWorldServiceImpl;

public class ServerTest {

    public static void main(String[] args) {
        System.out.println("Starting Server");
        HelloWorldServiceImpl helloWorldServiceImpl=new HelloWorldServiceImpl();
        String address="http://localhost:8090/helloWorldService";
        Endpoint.publish(address, helloWorldServiceImpl);
        System.out.println("Start success");

    }

}

運(yùn)行該類之后,該webservice就已經(jīng)發(fā)布了。

此時(shí),可以在其他的程序中調(diào)用該webservice了。

高度決定視野,角度改變觀念,尺度把握人生。

總結(jié)

以上是生活随笔為你收集整理的通过CFX发布WebService(一)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。