最近做的项目都是同webService有关的,自然就要关心一下webservice方面的资源。
http://www.wopos.com/webservice/Weather.asmx?op=getWeather 是一个天气预报的webservice,从它的输出结果来看天气数据应该来自中央气象局的问天网。过这方面就不用再多关心了,我们关心的是怎样调用这个webservice。
首先登录www.wopos.com/webservice/Weather.asmx?op=getWeather。可以看到如下的SOAP信息:
请求:
POST /webservice/Weather.asmx http/1.1
Host: www.wopos.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/getWeather"
<?
xml version="1.0" encoding="utf-8"
?>
<
soap:Envelope
xmlns:xsi
="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd
="http://www.w3.org/2001/XMLSchema"
xmlns:soap
="http://schemas.xmlsoap.org/soap/envelope/"
>
<
soap:Body
>
<
getWeather
xmlns
="http://tempuri.org/"
>
<
mCity
>
string
</
mCity
>
</
getWeather
>
</
soap:Body
>
</
soap:Envelope
>
XML部分全部复制下来创建一个XML文件(普通的文本文件也可以),为了以后编程方面,把
...
<
mCity
>
string
</
mCity
>
...
改成
...
<
mCity
>
${city}$
</
mCity
>
...
以weathersoap.xml保存在以后生成的类的同一目录。
响应:
http/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
<?
xml version="1.0" encoding="utf-8"
?>
<
soap:Envelope
xmlns:xsi
="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd
="h ttp://www.w3.org/2001/XMLSchema"
xmlns:soap
="h ttp://schemas.xmlsoap.org/soap/envelope/"
> <

本文介绍如何使用JAVA来调用一个天气预报的Webservice,通过解析SOAP信息,创建XML文件并进行测试,展示调用过程及结果。
最低0.47元/天 解锁文章
2262

被折叠的 条评论
为什么被折叠?



