Ê×Ò³ Ê«´Ê ×Öµä °å±¨ ¾ä×Ó ÃûÑÔ ÓÑ´ð ÀøÖ¾ ѧУ ÍøÕ¾µØͼ
µ±Ç°Î»ÖÃ: Ê×Ò³ > ½Ì³ÌƵµÀ > ÍøÕ¾¿ª·¢ > WebÇ°¶Ë >

ÈÝÒ×µÄwebService³ÌÐò

2012-12-28 
¼òµ¥µÄwebService³ÌÐò±¾ÊµÀýÖÐÐèÒªÒýÈëcxf-2.0.10.jarµÄjar°ü£¬ÔÚÁ´½Óhttp://192.168.0.122:8888/CXFWEBSer

¼òµ¥µÄwebService³ÌÐò
±¾ÊµÀýÖÐÐèÒªÒýÈëcxf-2.0.10.jarµÄjar°ü£¬ÔÚÁ´½Óhttp://192.168.0.122:8888/CXFWEBService/ÖеÄCXFWEBService ÊÇÏîÄ¿µÄÃû³Æ£¬

ÐèҪעÒâµÄÒ»µãÊÇ£º
ÔÚ·þÎñÆ÷¶Ë£¬Ê¹ÓõŤ³§ÊÇJaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();£¬
ÉèÖõÄclass ÊÇʵÏÖÀ࣬È磺factory.setServiceClass(SayHappyImpl.class);

ÔÚ¿Í»§¶Ë£º ʹÓõŤ³§ÊÇJaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
ÉèÖõÄclassÊǽӿڣ¬È磺factory.setServiceClass(SayHappy.class);

[ b]µÚÒ»²½£º ´´½¨Ò»¸ö½Ó¿Ú[/b]
package com.test.cxf.service.server;
import javax.jws.WebService;

// ×¢Ã÷webserviceµÄ½Ó¿Ú
@WebService
public interface SayHappy {

/**
* WebService½Ó¿Ú¶¨ÒåÀà.
*
* ʹÓÃ@WebService½«½Ó¿ÚÖеÄËùÓз½·¨Êä³öΪWeb Service.
* ¿ÉÓÃannotation¶ÔÉèÖ÷½·¨¡¢²ÎÊýºÍ·µ»ØÖµÔÚWSDLÖеĶ¨Òå.
*/

public String letMeSayHappy();

public String letKanasiiGo();

/**
* Ò»¸ö¸´Ôӵط½·¨£¬Í¨¹ý¶ÔÏóÀ´½»»¥
* @param
* @param
* @return
* @WebParam(name="xxxx")ÉèÖÃwsdlÎļþÖд«µÄ²ÎÊýµÄÃû³Æ
* @WebResult(name="xxxx")ÉèÖÃwsdlÎļþÖзµ»ØµÄ½á¹ûµÄÃû³Æ
*/
//public People changePeopleAge(String operName,String operPass);
}

µÚ¶þ²½£º´´½¨Ò»¸öÀ࣬ʵÏÖÉÏÃæµÄ½Ó¿Ú
package com.test.cxf.service.server;

import javax.jws.WebService;

/**
* WebService½Ó¿ÚµÄ¾ßÌåʵÏÖÀà
*
* @author
* @WebService(endpointInterface="xxxx") xxxxÖ¸Ïò½Ó¿ÚµÄȫ·¾¶
*/

// Õâ¸öʵÏÖÀàÉϵÄ×¢½âÈÃCXFÖªµÀÄĸö½Ó¿ÚÒª´´½¨ÎÒÃǵÄWSDLµÄ¡£
@WebService(endpointInterface = "com.test.cxf.service.server.SayHappy")
public class SayHappyImpl implements SayHappy {

public String letKanasiiGo() {
// TODO Auto-generated method stub
return "±¯¤·¤ß¤Ë¤µ¤è¤Ê¤é";
}

public String letMeSayHappy() {
// TODO Auto-generated method stub
return "ÐÒ¤»¤Ëß^¤´¤¹£¡";
}

}

µÚÈý²½£º´´½¨·þÎñÆ÷¶Ë£¬·¢²¼webservice
package com.test.cxf.service.server;

import org.apache.cxf.endpoint.Server;
import org.apache.cxf.jaxws.JaxWsServerFactoryBean;

public class SayHappyServer {

/**
* @param args
*/
public static void main(String[] args) {
JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();

//JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();



factory.setServiceClass(SayHappyImpl.class);//
factory.setAddress("http://192.168.0.122:8888/CXFWEBService/");

Server server = factory.create();

server.start();

}

}

Endpoint.publish("http://localhost:8080/helloWebService",new HelloWebServiceImpl()); ͬÑùÒ²ÊÇ·¢²¼·þÎñµÄ·½Ê½Ö®Ò»
µÚËIJ½£º´´½¨¿Í»§¶Ë½Ó¿Ú£¬·ÃÎÊwebservice
package com.test.cxf.service.server;

import org.apache.cxf.jaxws.JaxWsProxyFactoryBean; //cxf-2.0.10.jar

public class SayHappyClientTest {

public static void main(String[] args){

JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();

factory.setServiceClass(SayHappy.class);//
factory.setAddress("http://192.168.0.122:8888/CXFWEBService/");

SayHappy sayHappy = (SayHappy) factory.create();
System.out.println("webservice£º"+sayHappy.letMeSayHappy());

}

}

ÈȵãÅÅÐÐ