非常感谢孙浩老师。
@WebResult(name="user") public List<User> getAllUser(@WebParam(header=true,name="authInfo")String authInfo);
@Override public List<User> getAllUser(String authInfo) { System.out.println(authInfo); return users; }
测试类
/** * @Title: test06 * @Description: SOAP显示的创建和处理SOAPHeader的信息 * @param * @return void * @throws */ @Test public void test06() { try { // 创建访问wsdl服务的URL URL url = new URL("http://localhost:9999/ns?wsdl"); // 通过Qname指明服务的具体信息 QName name = new QName("http://soap.lichen.cn/","MyServiceImplService"); // 创建service Service service = Service.create(url,name); // 创建dispatch dispatch<SOAPMessage> dispatch = service.createdispatch(new QName( "http://soap.lichen.cn/","MyServiceImplPort"),SOAPMessage.class,Service.Mode.MESSAGE); // 创建SOAPmessage SOAPMessage message = MessageFactory.newInstance().createMessage(); SOAPEnvelope envelope = message.getSOAPPart().getEnvelope(); SOAPBody body = envelope.getBody(); QName qname = new QName("http://soap.lichen.cn/","getAllUser","xsd"); @SuppressWarnings("unused") SOAPBodyElement bodyElement = body.addBodyElement(qname); // 输入创建SOAPmessage message.writeto(System.out); System.out.println("\n\n" + "-----------invoking-------------" + "\n"); // 传递消息并且得到结果 SOAPMessage responseMessage = dispatch.invoke(message); // 输出得到的SOAPmessage responseMessage.writeto(System.out); // 将响应的消息转换为dom对象 Document doc = responseMessage.getSOAPBody() .extractContentAsDocument(); NodeList nl = doc.getElementsByTagName("user"); JAXBContext ctx = JAXBContext.newInstance(User.class); for (int i = 0; i < nl.getLength(); i++) { Node n = nl.item(i); User u = (User) ctx.createUnmarshaller().unmarshal(n); System.out.println("\n"+u.getNickname()); } } catch (SOAPException e) { e.printstacktrace(); } catch (IOException e) { e.printstacktrace(); } catch (JAXBException e) { e.printstacktrace(); } }
测试端:
服务端:
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。