java 访问Webservice 传递对象类型参数
public void send() throws Exception {
Map<String, Object> mpResult = null;
// 调用webService 来验证ID
Client client;
String url = "http://127.0.0.1:8080/GPSAS_WS_SENDMSG/SendMSGWS.ws?wsdl";
URL u = new URL(url);
client = new Client(u);
Object[] results = null;
client.setUrl("http://127.0.0.1:8080/GPSAS_WS_SENDMSG/SendMSGWS.ws");
// 实例化参数对象
SendMSG sengBean = new SendMSG();
sengBean.setMobileNumber("1366666666");
sengBean.setMessageContent("send");
List<SendMSG> lst = new ArrayList<SendMSG>();
lst.add(sengBean);
sengBean.setLstSend(lst);
// 序列化参数对象
ByteArrayOutputStream ba = out(sengBean);
System.out.println("-------ok----------" + ba);
results = client.invoke("test", new Object[] {ba});
String idCheckResult = results[0].toString();
System.out.println("-------ok----------" + idCheckResult);
}
/**
* 序列化
* @param sendBean
* @return
* @throws Exception
*/
public ByteArrayOutputStream out(SendMSG sendBean) throws Exception {
ByteArrayOutputStream buf = new ByteArrayOutputStream();
//把User对象序列化到一个字节缓存中
ObjectOutputStream out =new ObjectOutputStream(buf);
out.writeObject(sendBean);
byte[] buffer = buf.toByteArray();
return buf;
}
报异常:java.lang.ClassCastException
results = client.invoke("test", new Object[] {ba});
这里第二个参数应该转为什么类型,如何转换?
各位大侠请指点