Connect to an existing Web service: Try out the GoogleSearch API
Examining the WSDL in XMLSpy WSDL view, we see that it contains three operations listed on the right side under PortTypes:
Since searches on Google are a universally understood way to find information on the Web, the functionality of the doGoogleSearch Web service operation is easy to follow.
XMLSpy retrieves the remote WSDL and creates a SOAP request template for the doGoogleSearch operation, which we can examine in multiple views. Browser view displays the response with slightly different color coding than Text view. In Browser view the required search parameters are bold and black.
We can also expand the request in the XMLSpy Grid view to display its structure.
Either way, analysis of the SOAP request template indicates that Google requires more details than just a simple search string! Of course, we could study the Web service documentation to explore all the parameters, but to make things easier we can just copy the snippet of XML code below (which we adapted from Google's request example) and paste it into XMLSpy's text view as indicated in the next screenshot. Then all that's needed is to edit in our own account key and search string. Let's search for Ansel Adams. <key xsi:type="xsd:string">ENTER YOUR OWN ACCOUNT KEY HERE</key> <q xsi:type="xsd:string">Ansel Adams</q> <start xsi:type="xsd:int">0</start> <maxResults xsi:type="xsd:int">10</maxResults> <filter xsi:type="xsd:boolean">true</filter> <restrict xsi:type="xsd:string"/> <safeSearch xsi:type="xsd:boolean">true</safeSearch> <lr xsi:type="xsd:string"/> <ie xsi:type="xsd:string">latin1</ie> <oe xsi:type="xsd:string">latin1</oe>
When we're satisfied with the parameters, we can send the request to the GoogleSearch Web service using the XMLSpy SOAP menu:
Did you ever ask a simple question and get back an answer that was much more complicated than you expected? Our request generates a SOAP response from Google's Web service that comes back in the form of a verbose XML document. XMLSpy automatically opens the response in a new window:
(Note the size and position of the handle in the scrollbar at the upper right. The complete response is 167 lines long.)
If you're following along, open a new XSLT stylesheet v 1.0 in XMLSpy and paste in the commands below:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<p>Your search took <xsl:value-of select="//searchTime"/> seconds</p>
<p/>
<p>Estimated total number of results: <xsl:value-of select="//estimatedTotalResultsCount"/>
</p>
<xsl:for-each select="//item">
<xsl:call-template name="googleResult"/>
</xsl:for-each>
</xsl:template>
<xsl:template name="googleResult">
<p>
<a>
<xsl:attribute name="href"><xsl:value-of select="URL"/></xsl:attribute>
<xsl:value-of select="title" disable-output-escaping="yes"/>
</a>
</p>
<p>
<xsl:value-of select="snippet" disable-output-escaping="yes"/>
</p>
</xsl:template>
</xsl:stylesheet>
These commands can be saved in an XSLT file for reuse. Then, with the response file in our active window, we can use the XSL/Query menu to assign the XSLT file to the data we received.
Once the XSLT file is assigned to the SOAP response file, clicking on the XMLSpy Browser tab performs the transformation and displays the HTML as it would appear in Internet Explorer.
You can even click the hyperlinks to open any of the Web sites in the XMLSpy Browser window. (If you do visit one of the sites, click the Back arrow in the XMLSpy Browser toolbar, or the Text tab to return to the response file.)
In summary, we just used XMLSpy to:
You can apply these same strategies to learn about other existing Web services, whether they are operated by other public-facing companies or developed by other project teams within your own organization. XMLSpy makes it easy.
Google, eBay, Amazon, Yahoo! are trademarks or registered trademarks of their respective companies in the United States, other countries or both. Other company, product and service names may be trademarks or service marks of others. |
| ||||||||||||||||||||||
| 会社情報 | 企業法務 | プレス | パートナー | 求人情報 | サイトマップ | お問い合わせ | Altova Blog | Mobile | Full Site | |||
|
