实例讲解:Java中的SOAP技术
http://tech.ddvip.com 2006年11月25日 社区交流
本文详细介绍实例讲解:Java中的SOAP技术
用以下方式编译这个SOAP Client:
javac HelloWorldClient.java
为了圆满完成它,让我们检查一下针对我们的测试,是否所有事情都准备就绪。Tomcat正在运行,所有的环境变量都正确,SOAP Service被编译和部署,SOAP Client被成功编译。OK,让我们运行它,你将看到这个屏幕:

正如你所看到的,我们的SOAP Client使用SOAP协议成功发送它的名字和接收了一个答复。正如前面所说的,SOAP Service发送和接收的是SOAP envelope。这个是SOAP envelope的源代码。
被发送到SOAP Service的SOAP Envelope
<?xml version='1.0' encoding='UTF-8'?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/
soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/
XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Body>
<ns1:sayHi xmlns:ns1="urn:HelloWorld_SOAPService"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/
soap/encoding/">
<ourName xsi:type="xsd:string">Superman</ourName>
</ns1:sayHi>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>:从SOAP Service接收的SOAP Envelope
<?xml version='1.0' encoding='UTF-8'?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/
soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/
XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Body>
<ns1:sayHiResponse xmlns:ns1="urn:HelloWorld_SOAPService"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.
org/soap/encoding/">
<return xsi:type="xsd:string">Hello my friend, Superman!
Glad to see you!</return>
</ns1:sayHiResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>要理解SOAP Envelope中的所有标签的含义,我建议你花一点时间阅读 http://www.w3.org/2001/06/soap-envelope 命名空间规范。
我希望本文能够在你理解SOAP技术上有一定帮助。这个技术是简单的,有趣的,强大的,弹性的。它被用在许多Web应用中,这些应用的数量也在不断增加。学习SOAP是值得的,至少你要知道它是什么和它是怎么运作的。
责编:豆豆技术应用
正在加载评论...