Java远程调.net webservice例子

1 java调.net webservice:用懒人的方法:cxf java2wsdl 生成的客服端代码

2 以下就是一个真实成功的例子: axis 是1.4版本的
 

package test;


import javax.xml.namespace.QName;
public class Test {
    public static void main(String[] args) {
        //1.查看apache axis版本
        String v = org.apache.axis.Version.getVersion();
        System.out.println(v);
        try{
            //2.直接引用远程的wsdl文件
            String url = "http://zmd.skshu.com.cn/TMLS/anywell_webservice.asmx?wsdl";
            //以下都是套路
            org.apache.axis.client.Service service = new org.apache.axis.client.Service();
            org.apache.axis.client.Call call = (org.apache.axis.client.Call) service.createCall();
            call.setTargetEndpointAddress(new java.net.URL(url));
            //wsdl:definitions targetNamespace="http://tempuri.org/">
            //<wsdl:operation name="Get_WS"><wsdl:documentation>外部系统调用WebSerice.</wsdl:documentation><wsdl:input message="tns:Get_WSSoapIn"/><wsdl:output message="tns:Get_WSSoapOut"/></wsdl:operation>
            //3.设置输入参数
            call.setOperationName(new QName("http://tempuri.org/","Get_WS"));
            call.addParameter(new QName("http://tempuri.org/", "FSZID"),org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.IN);
            call.addParameter(new QName("http://tempuri.org/", "FPapaList"),org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.IN);
            call.addParameter(new QName("http://tempuri.org/", "FOutputFlag"),org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.IN);
            //4.设置返回参数
            call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);
            call.setUseSOAPAction(true);
            //5.设置SOAPaction
            //wsdl:operation name="Get_WS"><soap:operation soapAction="http://tempuri.org/Get_WS" style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation>
            call.setSOAPActionURI("http://tempuri.org/Get_WS");
            String xmlStr = call.invoke(new Object[]{ "", "", ""}).toString();
            System.out.println(xmlStr);
        }catch(Exception e){
            e.printStackTrace();
        }    
    }
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Terry谈企业数字化

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值