使用axis2远程访问webservice报错org.apache.axis2.AxisFault: 服务器无法处理请求。 ---> 未将对象引用设置到对象的实例。
wsdl的地址是:http://ws.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx?wsdl
代码如下:
package aixs;
import javax.xml.namespace.QName;
import org.apache.axis2.AxisFault;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.rpc.client.RPCServiceClient;
public class TestClient {
public static void main(String[] args) throws Exception {
System.out.println(testWebService());
}
public static String testWebService() throws Exception {
String result = null;
String srvcUrl = "http://ws.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx?wsdl";
QName qname = new QName("http://WebXml.com.cn/","getCountryCityByIp");
Object[] param= new Object[] {"42.20.56.23"};
try {
RPCServiceClient client = new RPCServiceClient();
Options options = new Options();
options.setTo(new EndpointReference(srvcUrl));
options.setAction("http://WebXml.com.cn/getCountryCityByIp");
client.setOptions(options);
Class[] returnTypes = new Class[] { String.class };
// 调用方法并输出该方法的返回值
Object[] response = client.invokeBlocking(qname, param, returnTypes);
result=(String) response[0];
} catch (AxisFault e) {
e.printStackTrace();
}
return result;
}
}