java调用webService

依赖包:

		<dependency>
            <groupId>org.apache.axis</groupId>
            <artifactId>axis</artifactId>
            <version>1.4</version>
        </dependency>
        <dependency>
            <groupId>commons-discovery</groupId>
            <artifactId>commons-discovery</artifactId>
            <version>0.5</version>
        </dependency>
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.0.4</version>
        </dependency>
        <dependency>
            <groupId>wsdl4j</groupId>
            <artifactId>wsdl4j</artifactId>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>dubbo-rpc-api</artifactId>
            <version>2.5.4-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>javax.xml</groupId>
            <artifactId>jaxrpc</artifactId>
            <version>1.1</version>
        </dependency>

测试代码:

package cn.com.bsoft.ssdev.boot.weixin.test;

import org.apache.axis.client.Call;
import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;
import javax.xml.rpc.ServiceException;
import javax.xml.rpc.encoding.XMLType;

import org.apache.axis.client.Service;
import static org.apache.axis.Constants.XSD_STRING;

public class MyTest {
    public static void main(String[] args) throws Exception {
        //doSelectRiskReportForm();
        String flag = getFlag("310108194104032427");
        System.out.println(flag);
    }
    public static void doSelectRiskReportForm() throws ServiceException {
        //调用接口
        //方法一:直接AXIS调用远程的web service
        try {
            String endpoint = "http://58.33.77.156:6887/get_report.asmx?wsdl";
            Service service = new Service();
            Call call = (Call) service.createCall();
            call.setTargetEndpointAddress(endpoint);
            String patientName = "310108194104032427"; 		// 参数名//对应的是 public String printWord(@WebParam(name = "settle_num") String settle_num);
//	            call.setOperationName("printWord");  		// 调用的方法名//当这种调用不到的时候,可以使用下面的,加入命名空间名
            call.setOperationName(new QName("http://tempuri.org/", "orientQueryLabReport"));// 调用的方法名
            call.setSOAPActionURI("http://tempuri.org/orientQueryLabReport");
            call.addParameter("sfzh", XSD_STRING, ParameterMode.IN);//参数名//XSD_STRING:String类型//.IN入参
            call.setReturnType(XSD_STRING); 	// 返回值类型:String
            String message = "310108194104032427";
            String result = (String) call.invoke(new Object[] { message });// 远程调用
            System.out.println("result is " + result);
        } catch (Exception e) {
            System.err.println(e.toString());
        }
    }

    public static String getFlag(String sfzh) throws Exception{
        String url = "http://58.33.77.156:6887/get_report.asmx?wsdl";
        String namespace_uri = "http://tempuri.org/";
        String soapActionURI = "http://tempuri.org/orientQueryLabReport";
        Service service=new Service();
        Call call = (Call)service.createCall();
        call.setTargetEndpointAddress(url);
        call.setUseSOAPAction(true);
        call.setSOAPActionURI(soapActionURI);
        call.setReturnType(XMLType.XSD_STRING);
        call.setOperationName(new QName(namespace_uri, "orientQueryLabReport"));

        // 所需参数
        call.addParameter(new QName(namespace_uri,"sfzh"),XMLType.XSD_STRING,ParameterMode.IN);
        // 执行,获取接口返回值
        return call.invoke(new Object[]{sfzh}).toString();
    }
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值