Microsoft’s Live Search APIs (http://msdn2.microsoft.com/en-us/library/bb251794.aspx
) are SOAP-based. The WSDL for version 1.1 is as follows:
http://soap.search.msn.com/webservices.asmx?wsdl
The Getting Started Guide is located here:
http://dev.live.com/blogs/livesearch/archive/2006/03/23/27.aspx
You need to set up an API ID (or get an existing one) to use the service; you can do this at the following location:
http://search.msn.com/developer
If you have access to Microsoft Visual Studio, I recommend trying the code samples:
http://msdn2.microsoft.com/en-us/library/bb251815.aspx
There are Express editions of Microsoft Visual Studio that are available for a free download:
http://www.microsoft.com/express/
Note | |
---|---|
In theory, because of the WSDL interface, you should be able to use Live.com in non-Microsoft environments. In practice, you will find it much easier to use Microsoft tools because the documentation and the samples are geared to those tools. To use other tools, I still refer to Microsoft tools to help me understand the important parameters. |
The search parameters for the Live Search API are more complicated than those for the Google SOAP search because the former uses complex, nested types. As I described in Chapter 7, there are a variety of ways to invoke WSDL-described SOAP calls. Some generate language-specific bindings. The one I find the easiest to understand is the approach taken by such tools as the WSDL/SOAP tools in XML Spy and oXygen: feed them the WSDL, and they determine the SOAP connection endpoint, the SOAPaction, and a template for the body. That combination of parameters allows you to call the method without resorting directly to any SOAP libraries.
Note | |
---|---|
XML Spy and oXygen are not free, although you can try them for 30 days free of charge. I don’t know of any freeware (except perhaps Eclipse) that makes it quite so easy to work with WSDL and SOAP. |
The search parameters are confusing, and it is not at all clear which parameters are mandatory without studying the WSDL directly; it’s also not clear what the valid parameters would be. For instance, I needed to study the following:
http://msdn2.microsoft.com/en-us/library/bb266177.aspx
to get help with the CultureInfo
field to figure out that an acceptable value is en-US
for American English.
Feeding the Live.com WSDL to XML Spy, you will get the following:
Connection endpoint: http://soap.search.msn.com:80/webservices.asmx
SOAPaction HTTP header: http://schemas.microsoft.com/MSNSearch/2005/09/fex/Search
The following template for a SOAP request:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Body>
<m:Search xmlns:m="http://schemas.microsoft.com/MSNSearch/2005/09/fex">
<m:Request>
<m:AppID>String</m:AppID>
<m:Query>String</m:Query>
<m:CultureInfo>String</m:CultureInfo>
<m:SafeSearch>Moderate</m:SafeSearch>
<m:Flags>None</m:Flags>
<m:Location>
<m:Latitude>3.14159265358979E0</m:Latitude>
<m:Longitude>3.14159265358979E0</m:Longitude>
<m:Radius>3.14159265358979E0</m:Radius>
</m:Location>
<m:Requests>
<m:SourceRequest>
<m:Source>Web</m:Source>
<m:Offset>0</m:Offset>
<m:Count>0</m:Count>
<m:FileType>String</m:FileType>
<m:SortBy>Default</m:SortBy>
<m:ResultFields>All</m:ResultFields>
<m:SearchTagFilters>
<m:string>String</m:string>
</m:SearchTagFilters>
</m:SourceRequest>
</m:Requests>
</m:Request>
</m:Search>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <SOAP-ENV:Body> <m:Search xmlns:m="http://schemas.microsoft.com/MSNSearch/2005/09/fex"> <m:Request> <m:AppID>String</m:AppID> <m:Query>String</m:Query> <m:CultureInfo>String</m:CultureInfo> <m:SafeSearch>Moderate</m:SafeSearch> <m:Flags>None</m:Flags> <m:Location> <m:Latitude>3.14159265358979E0</m:Latitude> <m:Longitude>3.14159265358979E0</m:Longitude> <m:Radius>3.14159265358979E0</m:Radius> </m:Location> <m:Requests> <m:SourceRequest> <m:Source>Web</m:Source> <m:Offset>0</m:Offset> <m:Count>0</m:Count> <m:FileType>String</m:FileType> <m:SortBy>Default</m:SortBy> <m:ResultFields>All</m:ResultFields> <m:SearchTagFilters> <m:string>String</m:string> </m:SearchTagFilters> </m:SourceRequest> </m:Requests> </m:Request> </m:Search> </SOAP-ENV:Body> </SOAP-ENV:Envelope>
If you just enter a key and a search term, no search results will come back. To figure out which parameters in the SOAP request are required and the range of possible values, start by reading this:
http://msdn2.microsoft.com/en-us/library/bb266182.aspx
which distinguishes between the following required parameters:
and the following optional parameters:
Flags
: One of None
, DisableHostCollapsing
, DisableSpellCheckForSpecialWords
, or MarkQueryWord
(None
is the default value)
Location
: The latitude, longitude, and optional search radius for the search
SafeSearch
: One of Strict
, Moderate
, or Off
(Moderate
is the default value)
Here’s a sample SOAP request that searches the Web for flower
in the American English context:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <SOAP-ENV:Body> <m:Search xmlns:m="http://schemas.microsoft.com/MSNSearch/2005/09/fex"> <m:Request> <m:AppID>[YOURKEY]</m:AppID> <m:Query>flower</m:Query> <m:CultureInfo>en-US</m:CultureInfo> <m:SafeSearch>Moderate</m:SafeSearch> <m:Flags>None</m:Flags> <m:Requests> <m:SourceRequest> <m:Source>Web</m:Source> </m:SourceRequest> </m:Requests> </m:Request> </m:Search> </SOAP-ENV:Body> </SOAP-ENV:Envelope>
This shows how to do this with curl
:
curl -H 'SOAPAction: "http://schemas.microsoft.com/MSNSearch/2005/09/fex/Search"' -d '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><SOAP-ENV:Body> <m:Search xmlns:m="http://schemas.microsoft.com/MSNSearch/2005/09/fex"><m:Request><m:AppID> [YOURKEY]</m:AppID> <m:Query>flower</m:Query><m:CultureInfo>en-US</m:CultureInfo> <m:SafeSearch>Moderate</m:SafeSearch> <m:Flags>None</m:Flags><m:Requests> <m:SourceRequest> <m:Source>Web</m:Source> </m:SourceRequest> </m:Requests> </m:Request></m:Search></SOAP-ENV:Body></SOAP-ENV:Envelope>' http://soap.search.msn.com:80/webservices.asmx
This will return a SOAP message with search results:
<?xml version="1.0" encoding="utf-8" ?> <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <soapenv:Body> <SearchResponse xmlns="http://schemas.microsoft.com/MSNSearch/2005/09/fex"> <Response> <Responses> <SourceResponse> <Source>Web</Source> <Offset>0</Offset> <Total>192000000</Total> <Results> <Result> <Title>Flowers, Roses, Plants, Gift Baskets - 1-800-FLOWERS.COM - Your ... </Title> <Description>Florist and gift retailer and franchisor with more than 100 stores nationwide offering online purchasing of arrangements, plants, gift baskets, confections and gourmet foods ... </Description> <Url>http://www.1800flowers.com/</Url> </Result> <Result> <Title>Flowers, plants, roses, & gifts. Flower delivery with fewer handlers ... </Title> <Description>Flowers, roses, plants and gift delivery. Order flowers from ProFlowers once, and you'll never use flower delivery from florists again</Description> <Url>http://www.proflowers.com/</Url> </Result> [...] </Results> </SourceResponse> </Responses> </Response> </SearchResponse> </soapenv:Body> </soapenv:Envelope>