java 板


LINE

各位前辈您好 小弟在工作上碰到了一个问题,我已经爬文过,也Google过了 我主要是阅读 The Java Web Services Tutorial For Java Web Services Developer's Pack, V2.0 February 17,2006 这本手册 现在所碰到的问题是 我想要将SOAP所回应的讯息的Body部份解读出来 例如Client送出讯息之後,Server端回应给Client端的SOAPMessage如下 <?xml version="1.0" encoding="UTF-8"?> <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> <S:Body> <ns2:sayHelloResponse xmlns:ns2="http://myself.idv.tw/"> <return>Hello!!!!</return> </ns2:sayHelloResponse> </S:Body> </S:Envelope> 此段讯息,我想要将Hello!!!!这个字在Client端印出来 但是 我试过了此手册的 P.133页的方法,都一直无法成功 请问各位前辈,有人能教我怎麽处理这段讯息,或者能给予我一些参考的资料吗?? 我在这地方卡了三天了,请各位帮忙 感谢 执行环境 Windows XP NetBeans, GlassFish V2.1, JDK 1.6.0_14 以下是我的程式码 主要分成: 1. Server端 2. Client端程式码 3. 我使用GlassFish的Web Service的Test所回应出来的讯息 4. 执行的结果 5. WSDL //========================================================================================= 1. Server端程式码: package tw.idv.myself; import javax.jws.WebMethod; import javax.jws.WebService; @WebService() public class Hello { @WebMethod(operationName = "sayHello") public String sayHello() { //TODO write your implementation code here: return "Hello!!!!"; } } //========================================================================================= 2. Client端程式码: public class Main { public static void main(String[] args) throws SOAPException, MalformedURLException, IOException { SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance(); SOAPConnection connection = soapConnectionFactory.createConnection(); MessageFactory factory = MessageFactory.newInstance(); SOAPMessage message = factory.createMessage(); SOAPHeader header = message.getSOAPHeader(); SOAPBody body = message.getSOAPBody(); QName bodyName = new QName("http://myself.idv.tw/", "sayHello", "ns2"); SOAPBodyElement bodyElement = body.addBodyElement(bodyName); URL endpoint = new URL("http://localhost:8080/MyServer/HelloService"); message.writeTo(System.out); //这边印出送出的讯息 System.out.println(""); SOAPMessage response = connection.call(message, endpoint); response.writeTo(System.out); //这边就是印出回应讯息 System.out.println(""); connection.close(); } //========================================================================================= 3. 我使用GlassFish的Web Service的test讯息 SOAP 请求 ----------------------------------------------------------------- <?xml version="1.0" encoding="UTF-8"?> <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> <S:Header/> <S:Body> <ns2:sayHello xmlns:ns2="http://myself.idv.tw/"/> </S:Body> </S:Envelope> ----------------------------------------------------------------- SOAP 回应 ----------------------------------------------------------------- <?xml version="1.0" encoding="UTF-8"?> <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> <S:Body> <ns2:sayHelloResponse xmlns:ns2="http://myself.idv.tw/"> <return>Hello!!!!</return> </ns2:sayHelloResponse> </S:Body> </S:Envelope> //===================================================================================== 4. 以下是执行Client端时所产生的讯息,我有自行分行过了 以下是送出时的SOAPMessage <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> <SOAP-ENV:Header/> <SOAP-ENV:Body> <ns2:sayHello xmlns:ns2="http://myself.idv.tw/"> <argo>Frederic</argo> </ns2:sayHello> </SOAP-ENV:Body> </SOAP-ENV:Envelope> //以下是回应时的SOAPMessage <?xml version="1.0" ?> <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> <S:Body> <ns2:sayHelloResponse xmlns:ns2="http://myself.idv.tw/"> <return>Hello!!!!</return> </ns2:sayHelloResponse> </S:Body> </S:Envelope> //===================================================================================== 5.WSDL <?xml version="1.0" encoding="UTF-8" ?> - <!-- Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.3.1-hudson-749-SNAPSHOT. --> - <!-- Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.3.1-hudson-749-SNAPSHOT. --> - <definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns: soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://myself.idv.tw/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://myself.idv.tw/" name="HelloService"> - <types> - <xsd:schema> <xsd:import namespace="http://myself.idv.tw/" schemaLocation="http://localhost:8080/MyServer/HelloService?xsd=1" /> </xsd:schema> </types> - <message name="sayHello"> <part name="parameters" element="tns:sayHello" /> </message> - <message name="sayHelloResponse"> <part name="parameters" element="tns:sayHelloResponse" /> </message> - <portType name="Hello"> - <operation name="sayHello"> <input message="tns:sayHello" /> <output message="tns:sayHelloResponse" /> </operation> </portType> - <binding name="HelloPortBinding" type="tns:Hello"> <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" /> - <operation name="sayHello"> <soap:operation soapAction="" /> - <input> <soap:body use="literal" /> </input> - <output> <soap:body use="literal" /> </output> </operation> </binding> - <service name="HelloService"> - <port name="HelloPort" binding="tns:HelloPortBinding"> <soap:address location="http://localhost:8080/MyServer/HelloService" /> </port> </service> </definitions> --



※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 59.125.136.75
1F:推 ppkkykei:NetBeans官网有web services教学文件. 06/16 00:12







like.gif 您可能会有兴趣的文章
icon.png[问题/行为] 猫晚上进房间会不会有憋尿问题
icon.pngRe: [闲聊] 选了错误的女孩成为魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一张
icon.png[心得] EMS高领长版毛衣.墨小楼MC1002
icon.png[分享] 丹龙隔热纸GE55+33+22
icon.png[问题] 清洗洗衣机
icon.png[寻物] 窗台下的空间
icon.png[闲聊] 双极の女神1 木魔爵
icon.png[售车] 新竹 1997 march 1297cc 白色 四门
icon.png[讨论] 能从照片感受到摄影者心情吗
icon.png[狂贺] 贺贺贺贺 贺!岛村卯月!总选举NO.1
icon.png[难过] 羡慕白皮肤的女生
icon.png阅读文章
icon.png[黑特]
icon.png[问题] SBK S1安装於安全帽位置
icon.png[分享] 旧woo100绝版开箱!!
icon.pngRe: [无言] 关於小包卫生纸
icon.png[开箱] E5-2683V3 RX480Strix 快睿C1 简单测试
icon.png[心得] 苍の海贼龙 地狱 执行者16PT
icon.png[售车] 1999年Virage iO 1.8EXi
icon.png[心得] 挑战33 LV10 狮子座pt solo
icon.png[闲聊] 手把手教你不被桶之新手主购教学
icon.png[分享] Civic Type R 量产版官方照无预警流出
icon.png[售车] Golf 4 2.0 银色 自排
icon.png[出售] Graco提篮汽座(有底座)2000元诚可议
icon.png[问题] 请问补牙材质掉了还能再补吗?(台中半年内
icon.png[问题] 44th 单曲 生写竟然都给重复的啊啊!
icon.png[心得] 华南红卡/icash 核卡
icon.png[问题] 拔牙矫正这样正常吗
icon.png[赠送] 老莫高业 初业 102年版
icon.png[情报] 三大行动支付 本季掀战火
icon.png[宝宝] 博客来Amos水蜡笔5/1特价五折
icon.pngRe: [心得] 新鲜人一些面试分享
icon.png[心得] 苍の海贼龙 地狱 麒麟25PT
icon.pngRe: [闲聊] (君の名は。雷慎入) 君名二创漫画翻译
icon.pngRe: [闲聊] OGN中场影片:失踪人口局 (英文字幕)
icon.png[问题] 台湾大哥大4G讯号差
icon.png[出售] [全国]全新千寻侘草LED灯, 水草

请输入看板名称,例如:Boy-Girl站内搜寻

TOP