Axis1增加SOAPHeader

   /** 
     * <soapenv:Header> 
     *     <ns:Authentication  
     *              soapenv:actor="http://schemas.xmlsoap.org/soap/actor/next"  
     *              soapenv:mustUnderstand="0"  
     *              xmlns="http://tempuri.org/"> 
     *         <ns:Username>admin</ns:Username> 
     *         <ns:Password>admin</ns:Password> 
     *     </ns:Authentication> 
     * </soapenv:Header> 
     * @param user 
     * @param password 
     */  
    public static void authentication(){  
        try {  
            Call call = (Call)new Service().createCall();  
            call.setTargetEndpointAddress("http://localhost:8080/ws/service/HelloWorld");  
            String namespace = "http://tempuri.org/";//命名空间  
            SOAPHeaderElement header = new SOAPHeaderElement(namespace,"Authentication");  
            header.setPrefix("ns");//前缀,如:ns1:name  
            header.addChildElement("Username").addTextNode(“admin”);    
            header.addChildElement("Password").addTextNode(“admin”);    
            call.addHeader(header);    
            Object obj = call.invoke("sayHi", new String[]{"sam"});  
            System.out.println(obj);  
        } catch (Exception e) {  
            e.printStackTrace();  
        }   
    }  

 

你可能感兴趣的:(header)