67,513
社区成员
发帖
与我相关
我的任务
分享
import java.net.MalformedURLException;
import java.rmi.RemoteException;
import javax.xml.rpc.ServiceException;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
public class T {
public static void main(String[] args) {
String endpoint = "http://www.webxml.com.cn/webservices/qqOnlineWebService.asmx?wsdl";
// 输入参数:QQ号码 String,默认QQ号码:xxxxxx。
// 返回数据:String,Y = 在线;N = 离线;E = QQ号码错误;A = 商业用户验证失败;V = 免费用户超过数量
Service service = new Service();
Call call;
try {
call = (Call) service.createCall();
call.setTargetEndpointAddress(new java.net.URL(endpoint));// 为Call设置服务的位置
// 设置要调用的方法
// call.setOperationName( new QName( "http://WebXml.com.cn/" ,
// "qqCheckOnline" ));
call.setOperationName("qqCheckOnline");
call.addParameter(new javax.xml.namespace.QName(
"http://WebXml.com.cn/", "qqCode"),
org.apache.axis.encoding.XMLType.XSD_STRING, String.class,
javax.xml.rpc.ParameterMode.IN);
call.setReturnType(XMLType.XSD_STRING);// 设置返回类型
// call.setReturnClass(String.class);
// 这个地方没设对就会出现Server was unable to read request的错误
// 如果.net在提供Rpc服务时设置成
// [SoapRpcMethod(Action = "",.....的话,那java客户端连
// call.setUseSOAPAction(true);
// call.setSOAPActionURI(soapActionURI);
// 2句都可以去掉了
call.setUseSOAPAction(true);
call.setSOAPActionURI("http://WebXml.com.cn/qqCheckOnline");
// http://WebXml.com.cn/ 命名空间
call.setOperationName(new javax.xml.namespace.QName(
"http://WebXml.com.cn/", "qqCheckOnline"));
String k = (String) call.invoke(new Object[] { "12345678" });
System.out.println("result is " + k.toString() + ".");
} catch (ServiceException e) {
// TODO
e.printStackTrace();
} catch (MalformedURLException e) {
// TODO
e.printStackTrace();
} catch (RemoteException e) {
// TODO
e.printStackTrace();
}
}
}
String url = "http://srv.mofun.cc/webservice/webservice.dll/soap/IWeather";
Service service = new Service();
Call call = (Call) service.createCall();
call.setOperationName(new QName("http://tempuri.org/",
"GetWeather"));
call.addParameter(new QName("http://tempuri.org/",
"CityNameOrCityNumber"), XMLType.XSD_STRING,
javax.xml.rpc.ParameterMode.IN);
//call.sets
call.setSOAPActionURI("urn:WeatherIntf-IWeather#GetWeather");
call.setTargetEndpointAddress(new URL(url));
call.setReturnType(XMLType.SOAP_VECTOR);
Vector<String> res = (Vector<String>) call.invoke(new Object[]{"鸡西"});
for (String str : res)
{
System.out.println(str);
}