JAVA调用.NET WebService接口获取输出参数的值

String s = null;
        try {
            String endpoint = "http://192.168.12.38:8181/ChinoeToChiva_WebService.asmx";
            /**创建一个服务(service)调用(call)*/
            Service service = new Service();
            /**通过service创建call对象*/
            Call call = (Call) service.createCall();
            /**设置service所在URL*/
            call.setTargetEndpointAddress(new java.net.URL(endpoint));
            QName qname = new QName("http://192.168.12.38:8181/","Check_C_PO");
            call.setOperationName(qname);
            call.addParameter("c_po",
                    org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
            call.addParameter("c_poLine",
                    org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
            call.addParameter("c_name",
                    org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
            call.setUseSOAPAction(true);
            /**返回参数的类型*/
            call.setReturnType(org.apache.axis.encoding.XMLType.SOAP_STRING);
            /**这个也要注意 就是要加上要调用的方法Add,不然也会报错*/
            call.setSOAPActionURI("http://tempuri.org/Check_C_PO");
            Object[] params = new Object[] {c_po,c_poLine,c_name};
            /**调用方法并传递参数 */
            System.out.println(call.invoke(params));
            s = (String) call.invoke(params);
            /**获得输出参数的值*/
            Map outparams = call.getOutputParams();
            if (outparams != null){
               /**迭代器迭代出输出参数的值*/
               Iterator ite = outparams.values().iterator();
               if (ite.hasNext()){
                  System.out.println(ite.next());
               }
            }
        } catch (Exception e) {
            System.err.println(e.toString());
        }

猜你喜欢

转载自blog.csdn.net/qq_42793618/article/details/83586802
今日推荐