A. java 咋把WebService發布到伺服器上
1、在Java項目中發布一個WebService服務,與Web服務相關的類,都位於Javax.jws.*包中。
@WebService 此註解用在類上指定將此類發布成一個WebService;
EndPoint 此類為端點服務類,其中publish()方法用於將一個已經添加了@WebService註解對象綁定到一個地址的埠上,用於發布。
<spanstyle="font-family:KaiTi_GB2312;font-size:18px;">packagecn.tgb.ws;
importjavax.jws.WebMethod;
importjavax.jws.WebService;
importjavax.xml.ws.Endpoint;
/**
*@WebService-它是一個註解,用在類上指定將此類發布成一個ws.
Endpoint–此類為端點服務類,它的方法publish用於將一個已經添加了@WebService註解對象綁定到一個地址的埠上。
*@authorxuemin
*
*/
@WebService
publicclassHelloWebService{
publicStringHelloWord(Stringname){
return"Hello:"+name;
}
/**
*添加exclude=true後,HelloWord2()方法不會被發布
*@paramname
*@return
*/
@WebMethod(exclude=true)
publicStringHelloWord2(Stringname){
return"Hello:"+name;
}
publicstaticvoidmain(String[]args){
/**
*參數1:服務的發布地址
*參數2:服務的實現者
*/
Endpoint.publish("服務發布地址",newHelloWebService());
}
}
</span>
註:@WebService 它是一個註解,用在類上指定將此類發布成一個ws,Endpoint 此類為端點服務類,它的方法publish用於將一個已經添加了@WebService註解對象綁定到一個地址的埠上。運行以上程序即可進行WebService發布。