java 调用WebService

导入jar包
<dependency>
    <groupId>org.apache.axis</groupId>
    <artifactId>axis</artifactId>
    <version>1.4</version>
</dependency>

<dependency>
    <groupId>org.lucee</groupId>
    <artifactId>jaxrpc</artifactId>
    <version>1.4.0</version>
</dependency>
<dependency>
    <groupId>commons-discovery</groupId>
    <artifactId>commons-discovery</artifactId>
    <version>0.5</version>
</dependency>
<dependency>
    <groupId>wsdl4j</groupId>
    <artifactId>wsdl4j</artifactId>
    <version>1.6.2</version>
</dependency>


java方法
public void callMeth() throws RemoteException, javax.xml.rpc.ServiceException, MalformedURLException {
    String url = "http://jsxngx.seu.edu.cn/WebService/ResourceService.asmx";//提供接口的地址
    String soapaction = "http://tempuri.org/";   //命名空间 和webservic中的targetNamespace对应
    String json = "{\n" +
            "    \"UnitCode\": \"320001\",\n" +
            "    \"Account\": \"admin\",\n" +
            "    \"PushTime\": \"201710122523002\",\n" +
            "    \"EvaluationReportMainList\": [\n" +
            "        {\n" +
            "            \"ResourceName\": \"实验资源名称1\",\n" +
            "            \"EvaluationReportList\": [\n" +
            "                {\n" +
            "                    \"UserName\": \"评价人1\",\n" +
            "                    \"UserNo\": \"123\",\n" +
            "                    \"EvaluationContent\": \"评价内容\",\n" +
            "                    \"CreateDate\": \"/Date(1512573800000)/\"\n" +
            "                }\n" +
            "            ]\n" +
            "        },\n" +
            "        {\n" +
            "            \"ResourceName\": \"实验资源名称2\",\n" +
            "            \"EvaluationReportList\": [\n" +
            "                {\n" +
            "                    \"UserName\": \"评价人2\",\n" +
            "                    \"UserNo\": \"124\",\n" +
            "                    \"EvaluationContent\": \"评价内容\",\n" +
            "                    \"CreateDate\": \"/Date(1512573800000)/\"\n" +
            "                }\n" +
            "            ]\n" +
            "        }\n" +
            "    ]\n" +
            "}" ;
    Service service = new Service();
    Call call =  (Call) service.createCall();
    call.setTargetEndpointAddress(new java.net.URL(url));
    call.setOperationName(new QName(soapaction, "AddEvaluationReport"));//命名空间 调用的方法名
    call.addParameter(new QName(soapaction ,"json"), Constants.XSD_STRING, javax.xml.rpc.ParameterMode.IN);//传递的参数
    call.setReturnType(Constants.XSD_BOOLEAN);//(标准的类型)
    call.setUseSOAPAction(true);
    call.setSOAPActionURI(soapaction + "AddEvaluationReport");
    Boolean aa =(Boolean) call.invoke(new String[]{json});
    System.out.println(aa);//输出返回值
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值