Óû§Ãû£ºzixuan881°Ù0
packageclient;imʾÂÛÓê¹ÛÇ°ÓýÂÌÉú¹ÛÉ«¹ãportj**ax.xml.namespace.ÐÂÇÒ±à»**ÖҺëQName;
importorg.apache.axis2.addressing.EndpointReference;
importorg.apache.axis2.client.Options;
importorg.apache.axis2.rpc.client.RPCServiceClient;publicclassRPCClient
{
publicÀ´×Ôstaticvoidmain(String[]ÎÊ´ðargs)throwsException
{
//ʹ±ß³Á×ÓÈõά³ªÉ¢²ãÑÏ·çÓÃRPC·½Ê½µ÷ÓÃWebService
RPCServiceClientserviceClient=newRPC×൱ÉÏÉ«ÐÂÔ˵۶ÊÅ®ServiceClient();
Option»÷¼þ³£Ì¬´ð×soptions=servÓêÀ§ÔÙ³ÐÇéÔõ°¡ÑÓiceClient.getOptions();
//Ö¸¶¨µ÷ÓÃWebServiceµÄURL
EndÒËÏ£Î÷³ÖpointReferencetargetEPR=newEndpointReference(
"http://localhost:8080/axis2/services/SimpleService");
options.setTo(targetEPR);
//Ö¸¶¨getGreeting·½·¨µÄ²ÎÊýÖµ
ObjectÎȹ¤µÃÌØÈ¥¹â¹¹[]opAddEntryAÁ¿Á÷»ªrgs=newObject[]{"³¬ÈË"};
//Ö¸¶¨getGreeting·½·¨·µ»ØÖµµÄÊýʱæþÝÀàÐ͵ÄClass¶ÔÏó
Class[]classes=newClass[]{String.class};
//Ö¸¶¨Òªµ÷ÓõÄgetGreeting·½·¨¼°WSDLÎļþµÄÃüÃû¿Õ¼ä
QNameopAddEntr»¤¸ßÓÅÔËëÓɹÌy=newQName("http://ws.apÊÓ×¼°û²¡¹¥Âýache.org/axÄÍͶֻ°ûËis2","getGÔÓ¿ÉÈâ±¾ÏÂÏÖÂ̸ɰÉÊäreeting");
//µ÷ÓÃgetGreetiת²î²éÆ·ÊÒ¹¥ng·½·¨²¢Êä³ö¸Ã·½·¨´¬·þÏ·¹ÔºÓêÔ±¶Ëζ·çµÄ·µ»ØÖµ
System.out.println(serviceClient.invokeBlocking(opAddEÈ¡¸É¾öÈ¡Õ¼½µntry,opAddEntryArgs,classes)[0]);
//ÏÂÃæÊǵ÷ÓÃgetPrice·½·¨µÄ´úÂ룬ÕâЩ´úÂëÓëµ÷ÓÃgetGreeting·½·¨µÄ´úÂëÀàËÆ
classes=newClass[]{int.class};
opAddEntry=newQName("http://ws.apache.org/axis2","getPrice");
System.out.println(serviceClient.invokeBlocking(opAddEntry,newObject[]{},classes)[0]);
}
}ps:¸øÄã¸öj**a·½·¨£¬¸Ä¸Ä¾ÍºÃÁË