5
Axis WebService ¼¼ÊõÖ¸ÄÏ
} } QName qname = new QName(\, //Ö¸¶¨µ÷Óõķ½·¨ºÍ´«µÝ²ÎÊýÊý¾Ý£¬¼°ÉèÖ÷µ»ØÖµµÄÀàÐÍ Object[] result = client.invokeBlocking(qname, new Object[] System.out.println(result[0]); qname = new QName(\, \); result = client.invokeBlocking(qname, new Object[] { new System.out.println(result[0]); \); { \ }, new Class[] { String.class }); Integer(22) }, new Class[] { int.class }); Èç¹ûÄãÁ˽â»òÊÇ¿´¹ýaxis1.xµÄWebService£¬ÕâÀïµÄ¿Í»§¶Ëµ÷ÓôúÂë±È½Ï¼òµ¥£¬Óв¿·Ö¹Ø¼ü×¢ÊÍ£¬ÕâÀï¾Í²»¶à¼Ó׸Êö¡£ÖµµÃ×¢ÒâµÄÊÇaxis2µÄWebService¿Í»§¶Ëµ÷Óõķµ»Ø¶ÔÏóÊÇÒ»¸öObjectµÄÊý×飬ÕâµãºÍaxis1.xÓкܴó²»Í¬¡£ÎÒÃÇÒ»°ãÄÃÊý×éµÄµÚÒ»¸öÖµ£¬×ª»»Ç¿×ª¼´¿É¡£
Èý¡¢ ¸´ÔÓ¶ÔÏóÀàÐ͵ÄWebService
1¡¢Õâ´ÎÎÒÃDZàд¸´ÔÓµãµÄWebService·½·¨£¬·µ»ØµÄÊý¾ÝÊÇÎÒÃǶ¨ÒåÊôÐÔ´øgetter¡¢setter·½·¨JavaBean£¬Ò»Î¬Êý×é¡¢¶þάÊý×éµÈ¡£ ¿´´úÂ룺
import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.util.Random; import data.User; /** * function:¸´ÔÓÀàÐÍÊý¾ÝµÄWebService£º×Ö½ÚÊý×é¡¢·µ»ØÒ»Î¬intÊý×é¡¢¶þάStringÊý×é¼°×Ô¶¨ÒåJavaBean¶ÔÏóµÈ * @author hoojo * @createDate 2011-1-13 ÏÂÎç03:34:52 * @file ComplexTypeService.java * @package * @project Axis2WebService * @blog http://blog.csdn.net/IBM_hoojo * @email hoojo_@126.com * @version 1.0 */ public class ComplexTypeService { public String upload4Byte(byte[] b, int len) { String path = \; »¶Ó×ªÔØ Çë±£ÁôÔÎÄ×÷ÕßÐÅÏ¢ ²»µÃδ¾×÷ÕßÔÊÐíÓÃÓÚÉÌÒµÓÃ;
6
Axis WebService ¼¼ÊõÖ¸ÄÏ
}
FileOutputStream fos = null; try {
String dir = System.getProperty(\); File file = new File(dir + \ + new fos = new FileOutputStream(file); fos.write(b, 0, len);
path = file.getAbsolutePath(); System.out.println(\ +
Random().nextInt(100) + \);
file.getAbsolutePath());
} catch (Exception e) { }
return path;
e.printStackTrace(); try { }
fos.close();
e.printStackTrace(); } catch (IOException e) { } finally {
public int[] getArray(int i) { }
public String[][] getTwoArray() {
return new String[][] { { \Öйú\, \±±¾©\ }, { \ÈÕ±¾\, \¶«¾©int[] arr = new int[i]; for (int j = 0; j < i; j++) { }
return arr;
arr[j] = new Random().nextInt(1000);
\ }, { \Öйú\, \ÉϺ£\, \ÄϾ©\ } }; } }
public User getUser() { }
User user = new User(); user.setAddress(\); user.setEmail(\); user.setName(\); user.setId(22); return user;
»¶Ó×ªÔØ Çë±£ÁôÔÎÄ×÷ÕßÐÅÏ¢ ²»µÃδ¾×÷ÕßÔÊÐíÓÃÓÚÉÌÒµÓÃ;
7
Axis WebService ¼¼ÊõÖ¸ÄÏ
ÉÏÃæµÄWebService·þÎñ·Ö±ðÊÇ´«µÝ×Ö½ÚÍê³ÉÊý¾ÝÉÏ´«£¬·µ»ØÒ»Î¬intÊý×éºÍ¶þά×Ö·û´®Êý×飬ÒÔ¼°·µ»ØUser JavaBean¶ÔÏó¡£ ÏÂÃæ¿´¿´User Bean´úÂ룺
package data;
import java.io.Serializable; /**
* function:User Entity * @author hoojo
* @createDate Dec 16, 2010 10:20:02 PM * @file User.java
* @package com.hoo.entity * @project AxisWebService
* @blog http://blog.csdn.net/IBM_hoojo * @email hoojo_@126.com * @version 1.0 */
public class User implements Serializable { }
@Override
public String toString() { }
return this.id + \ + this.name + \ + this.email + \ private static final long serialVersionUID = private int id; private String name; private String email; private String address;
//getter/setter 677484458789332877L;
+ this.address;
ÖµµÃ×¢ÒâµÄÊÇÕâ¸öUser¶ÔÏóµÄpackageÊÇdata£¬Èç¹ûÊÇÆäËüµÄpackage£¬Äã¾ÍÐèÒªÔÚtomcatĿ¼ÏµÄwebappsÖеÄaxis2µÄWEB-INFĿ¼Ï´´½¨Ò»¸ödataĿ¼£¬ºÍÄãµÄUser¶ÔÏóµÄĿ¼±£³ÖÒ»Ö¡£·ñÔòÄãµÄWebService½«»á³öÏÖClassNotFontExceptionÒì³£¡£È»ºóÖØÆôÄãµÄtomcat£¬ËäÈ»axis2Ö§³ÖÈȲ¿Êð¡£ 2¡¢±àдµ÷ÓÃÉÏÃæWebServiceµÄ¿Í»§¶Ë´úÂ룬´úÂëÈçÏ£º package com.hoo.service; import java.io.File; import java.io.FileInputStream; import java.io.IOException; »¶Ó×ªÔØ Çë±£ÁôÔÎÄ×÷ÕßÐÅÏ¢ ²»µÃδ¾×÷ÕßÔÊÐíÓÃÓÚÉÌÒµÓÃ;
8
Axis WebService ¼¼ÊõÖ¸ÄÏ
import javax.xml.namespace.QName;
import org.apache.axis2.addressing.EndpointReference; import org.apache.axis2.client.Options;
import org.apache.axis2.rpc.client.RPCServiceClient; import com.hoo.entity.User; /**
* function:¸´ÔÓÀàÐÍÊý¾ÝWebService¿Í»§¶Ëµ÷ÓôúÂë * @author hoojo
* @createDate 2011-1-13 ÏÂÎç03:36:38 * @file ComplexTypeServiceClient.java * @package com.hoo.service * @project Axis2WebService
* @blog http://blog.csdn.net/IBM_hoojo * @email hoojo_@126.com * @version 1.0 */
public class ComplexTypeServiceClient {
public static void main(String[] args) throws IOException {
RPCServiceClient client = new RPCServiceClient(); Options options = client.getOptions(); String address =
EndpointReference epr = new EndpointReference(address); options.setTo(epr);
QName qname = new QName(\, String path = System.getProperty(\); File file = new File(path + \); FileInputStream fis = new FileInputStream(file); int len = (int) file.length(); byte[] b = new byte[len]; int read = fis.read(b);
//System.out.println(read + \+ len + \+ new String(b)); fis.close();
Object[] result = client.invokeBlocking(qname, new Object[] System.out.println(\ + result[0]);
qname = new QName(\,
result = client.invokeBlocking(qname, new Object[] { 3 }, \;
\);
{ b, len }, new Class[] { String.class });
\);
»¶Ó×ªÔØ Çë±£ÁôÔÎÄ×÷ÕßÐÅÏ¢ ²»µÃδ¾×÷ÕßÔÊÐíÓÃÓÚÉÌÒµÓÃ;
9
Axis WebService ¼¼ÊõÖ¸ÄÏ
new Class[] { int[].class }); }
}
int[] arr = (int[]) result[0]; for (Integer i : arr) { }
qname = new QName(\,
result = client.invokeBlocking(qname, new Object[] {}, new String[][] arrStr = (String[][]) result[0]; for (String[] s : arrStr) { }
qname = new QName(\,
result = client.invokeBlocking(qname, new Object[] {}, new User user = (User) result[0];
System.out.println(\ + user);
for (String str : s) { }
System.out.println(\ + str); System.out.println(\ + i);
\);
Class[] { String[][].class });
\);
Class[] { User.class });
ÉÏÃæµÄ´úÂëÔËÐкóµÄ½á¹ûÊÇ£º upload:D:\\tomcat-6.0.28\\bin\\28.jsp int[] :548 int[] :201 int[] :759 String[][]: Öйú String[][]: ±±¾© String[][]: ÈÕ±¾ String[][]: ¶«¾© String[][]: Öйú String[][]: ÉϺ£ String[][]: ÄϾ© User: 22#jack#jack@223.com#china
ËÄ¡¢ ÓÃaxis2µÄ¸¨Öú¹¤¾ß·¢²¼¡¢µ÷ÓÃWebService
Õâ´ÎÎÒÃDZà¼Ò»¸ö·µ»ØUser¶ÔÏó¡¢List
ÏÂÃæ¿´¿´·þÎñÆ÷¶ËWebService´úÂ룺
»¶Ó×ªÔØ Çë±£ÁôÔÎÄ×÷ÕßÐÅÏ¢ ²»µÃδ¾×÷ÕßÔÊÐíÓÃÓÚÉÌÒµÓÃ;
Ïà¹ØÍÆ¼ö£º