java webservice异常处理_java方法调用.net的webservice接口的异常求助

需求:用java方法调用客户的.net的webservice接口方法。

问题:

网上找了一个java调用.net的ws服务接口的方法,然后调用网上的天气预报web服务,但是输入参数报错----服务器无法处理请求。 —> 值不能为空。

3f3abed927d52cb28019e9b117dbe58a.png

实际就只有一个参数啊!还不叫input!而且我传了!!

代码如下:

==================================================

package com.jay.demo.webservice.dynamic;

import org.apache.axis.client.Call;

import org.apache.axis.client.Service;

import org.apache.ws.commons.schema.constants.Constants;

import javax.xml.namespace.QName;

/**

@Author 99

@Date 2019/5/22 13:44

@Description 动态调用.net版本的webservice接口客户端

**/

public class WSNetServerDynamicClient {

public static void main(String[] args) {

Textaxis();

}

//通过axis方式调用webservice接口

public static void Textaxis() {

try {

// 指出service所在完整的URL

String endpoint = "http://ws.webxml.com.cn/WebServices/WeatherWS.asmx?wsdl";

//调用接口的targetNamespace

//targetNamespace 就是你用浏览器打开endpoint 路径加上?wsdl,即http://xxx/WebService1.asmx?wsdl 中的targetNamespace属性值

String targetNamespace = "http://WebXml.com.cn/";

//所调用接口的方法method

String method = "getSupportCityString";

// 创建一个服务(service)调用(call)

Service service = new Service();

Call call = (Call) service.createCall();// 通过service创建call对象

// 设置service所在URL

call.setTargetEndpointAddress(new java.net.URL(endpoint));

call.setOperationName(new QName(targetNamespace, method));

call.setUseSOAPAction(true);

call.setSOAPActionURI("http://WebXml.com.cn/getSupportCityString");

//变量最好只是用String类型,其他类型会报错

call.addParameter(new QName(targetNamespace, "getSupportCityString"),

Constants.XSD_STRING,

javax.xml.rpc.ParameterMode.IN);//设置参数名 state  第二个参数表示String类型,第三个参数表示入参

call.setReturnType(Constants.XSD_STRING);// 设置返回类型

String jsonString = (String) call.invoke("getSupportCityString",new Object[]{"苏州"});//此处为数组,有几个变量传几个变量

System.out.println(jsonString);

} catch (Exception e) {

e.printStackTrace();

}

}

}

==================================================

附上调用网上的天气预报web服务wsdl地址:

http://ws.webxml.com.cn/WebServices/WeatherWS.asmx?wsdl

急求大家帮助啊!!!!!!!!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值