java远程调.net webservice例子

来源:互联网 发布:中国沿海湿地保护网络 编辑:程序博客网 时间:2024/06/05 01:11

// java调.net webservice:用懒人的方法:cxf java2wsdl 生成的客服端代码后,发现在客户端找不到对应的方法,问了百老师之后,尝试一番,最终成功了,thanks bai.

//以下就是一个真实成功的例子: 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 0
原创粉丝点击