得到这个对象之后,添加soap header的方法有如下几种
1,使用addStringHeader方法
_serviceClient.addStringHeader(new QName("preifx", "field", "Ns"), "header value");
2,使用addHeader(SOAPHeaderBlock header)方法
SOAPFactory factory = OMAbstractFactory.getSOAP12Factory(); OMNamespace ns = factory.createOMNamespace("http://ws.apache.org/axis2", "hns"); SOAPHeaderBlock shb; shb = factory.createSOAPHeaderBlock("field", ns); shb.setText("value"); _serviceClient.addHeader(shb);
3,使用addHeader(OMElement header)方法
或者自己创建一个OMElement对象,或者使用stub里面的这些内部类提供的方法生成
OMFactory omFactory = OMAbstractFactory.getOMFactory(); OMElement omElement = omFactory.createOMElement(new QName("prefix", "field", "Ns"), null); omElement.setText("value"); hereclient.addHeader(omElement);
RequestSOAPHeaderE rshe = new RequestSOAPHeaderE(); rshe.setRequestSOAPHeader(header); _serviceClient.addHeader(rshe.getOMElement(null, OMAbstractFactory.getOMFactory()));
RequestSOAPHeaderE和RequestSOAPHeader都是Axis2根据wsdl文件自动生成的对象