Webservice_12_传递SOAP的消息和处理
2013-08-01 15:38
337 查看
非常感谢孙浩老师。
得到结果:
/** * @Title: test02 * @Description: 用SOAPMessage传递SOAP的消息和处理 * @param * @return void * @throws */ @Test public void test02() { 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/", "add", "xsd"); SOAPBodyElement bodyElement = body.addBodyElement(qname); bodyElement.addChildElement("a").setValue("50"); bodyElement.addChildElement("b").setValue("34"); //输入创建SOAPmessage message.writeTo(System.out); System.out.println("\n"+"-----------invoking-------------"); //传递消息并且得到结果 SOAPMessage responseMessage = dispatch.invoke(message); //输出得到的SOAPmessage responseMessage.writeTo(System.out); //将响应的消息转换为dom对象 Document doc = responseMessage.getSOAPPart().getEnvelope().getBody().extractContentAsDocument(); String str = doc.getElementsByTagName("addResult").item(0).getTextContent(); System.out.println("\n"+str); } catch (SOAPException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
得到结果:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header/><SOAP-ENV:Body><xsd:add xmlns:xsd="http://soap.lichen.cn/"><a>50</a><b>34</b></xsd:add></SOAP-ENV:Body></SOAP-ENV:Envelope> -----------invoking------------- <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Header/><S:Body><ns2:addResponse xmlns:ns2="http://soap.lichen.cn/"><addResult>84</addResult></ns2:addResponse></S:Body></S:Envelope> 84
相关文章推荐
- Webservice_13_Payload的方式传递SOAP的消息和处理 和 用SOAPMessage传递SOAP的消息和处理(无参数)
- soap消息的传递与处理(二)(基于payload的方式)
- SOAP消息的创建、传递和处理(MESSAGE方式)
- soap消息分析和soap消息的传递和处理(一)
- SOAP消息的传递和处理(PAYLOAD方式)
- SOAP消息的创建,传递,处理的学习笔记
- soap消息的传递和处理(三)——包含header和异常的处理
- Webservice06---SOAP消息的传递和处理(基于Message方式)
- soap消息传递和处理(基于Message和Payload的方式)
- SOAP消息头的处理
- EDI 解决方案之•EDI 消息传递•协议在 EDI 处理中的角色
- twitter storm 源码走读之5 -- worker进程内部消息传递处理和数据结构分析
- 通过HTTP请求,将XML以SOAP消息的方式发给JWSDP、.NET的webservice
- 一个能够检查Windows传递给窗口消息处理程序的键盘内容和字符消息的程序
- JAX-WS创建和处理SOAP消息
- WebService大讲堂之Axis2(10):使用soapmonitor模块监视soap请求与响应消息
- webservice入门笔记二soap消息的处理
- WebService大讲堂之Axis2(10):使用soapmonitor模块监视soap请求与响应消息
- SOAP消息的传递
- Android事件处理之四 Handler消息传递机制