Webservice Macro Example - Bing Search

This example demonstrates the usage of the se:webservice macro. It will call the Bing Search webservice with a fixed search term and uses the se:xslt capabilities of the format parameter to transform the result into a html lay-out (a webservice will usually return the result in xml format).

Note: to use the Bing webservice you would need a developer key (AppId).

When you want to contact a webservice using the se:webservice macro, you should first examine the WSDL (if available) of the webservice. This should point you in the right direction which macro parameters are needed and what information must be provided within these parameters.

Then, when developing the webservice interaction, it can be usefull to first display the raw xml result. From there on, you will be able to write the se:xslt necessary to transform the xml result into a (html) format you want.

Smartsite SXML CopyCode image Copy Code
<se:webservice>
    <se:parameters>
        <se:parameter name="url">http://api.bing.net/soap.asmx</se:parameter>
        <se:parameter name="soapaction">http://schemas.microsoft.com/LiveSearch/2008/03/Search/Search</se:parameter>
        <se:parameter name="literalmethodnode">
            <SearchRequest xmlns="http://schemas.microsoft.com/LiveSearch/2008/03/Search">
                <parameters>
                    <Query>Smartsite iXperion</Query>
                    <AppId>-- your AppId --</AppId>
                    <Sources><SourceType>Web</SourceType></Sources>
                    <Web><Count>10</Count></Web>
                </parameters>
            </SearchRequest>
        </se:parameter>
        <se:parameter name="format">
            <se:xslt>
                <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
                        xmlns:b="http://schemas.microsoft.com/LiveSearch/2008/03/Search" version="1.0">
                    <xsl:output method="html" indent="yes"/>
                    <xsl:template match="/">
                        <xsl:element name="p">
                            The following results were found for '<xsl:value-of select="//b:SearchTerms" />'.
                        </xsl:element>

                        <xsl:for-each select="//b:WebResult">
                            <xsl:element name="p">
                                <xsl:element name="a">
                                    <xsl:attribute name="href">http://<xsl:value-of select="b:DisplayUrl"/>
                                    </xsl:attribute>
                                    <xsl:value-of select="b:Title" disable-output-escaping="yes"/>
                                </xsl:element>
                                <br/>
                                <xsl:value-of select="b:Description" disable-output-escaping="yes"/>
                                <br/> 
                                <xsl:element name="span">
                                    <xsl:element name="font">
                                        <xsl:attribute name="style">color:green</xsl:attribute>
                                        <xsl:value-of select="b:DisplayUrl"/>                                        
                                    </xsl:element>
                                </xsl:element>
                            </xsl:element>
                        </xsl:for-each>
                    </xsl:template>
                </xsl:stylesheet>
            </se:xslt>
        </se:parameter>
    </se:parameters>
</se:webservice>
Example Result CopyCode image Copy Code
<!-- html containing bing search result -->