zoukankan      html  css  js  c++  java
  • java 调用webservice接口(asmx)

    进入.asmx的链接,找到方法名、命名空间等

    import javax.xml.namespace.QName;
    
    import org.apache.axis.client.Call;
    import org.apache.axis.client.Service;
    import org.apache.axis.message.SOAPHeaderElement;
    
    /**
     * Created by liwj on 2017/6/15.
     */
    public class AsmxTest {private static String urlhsb="";
        private static String namespaceURI="";
    
        public static void main(String[] args){
            String xsXml="";
            Service service=new Service();
            try {
                Call call=(Call)service.createCall();
                call.setTargetEndpointAddress(urlhsb);
                //设置要调用哪个方法
                call.setOperationName(new QName(namespaceURI,"GetCbzm"));
                call.addParameter(new QName(namespaceURI,"xml"),
                        org.apache.axis.encoding.XMLType.XSD_STRING,
                        javax.xml.rpc.ParameterMode.IN);
                call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);
                call.setUseSOAPAction(true);
                call.setSOAPActionURI(namespaceURI);
    
                //设置soapHeader
                SOAPHeaderElement soapHeaderElement = new SOAPHeaderElement(namespaceURI, "ValidationSoapHeader");
                soapHeaderElement.setNamespaceURI(namespaceURI);
                try {
                    soapHeaderElement.addChildElement("UserName").setValue("");
                    soapHeaderElement.addChildElement("PassWord").setValue("");
                    call.addHeader(soapHeaderElement);
                }catch (Exception e){
    
                }
    
                String res=String.valueOf(call.invoke(new Object[]{xsXml}));
    
                System.out.println(res);
    
    
            }catch (Exception e){
                System.out.println(e.getMessage());
            }
        }
    }
  • 相关阅读:
    主机不能访问虚拟机CentOS中的站点
    linux安装redis
    java获去json所有对象
    Java nio和io
    [shell基础]——if/for/while/until/case 语句
    [shell基础]——整数比较;字符串比较;文件测试;逻辑测试符
    [shell基础]——数组
    [shell基础]——I/O重定向
    [shell基础]——tr命令
    [shell基础]——split命令
  • 原文地址:https://www.cnblogs.com/zuferj115/p/7052952.html
Copyright © 2011-2022 走看看