index > Windows Live Search: Development > MSN Search API implemented in ASP only

MSN Search API implemented in ASP only

Hello!

I've been working hard for a couple of days to implement the search API's of Google, Yahoo, and MSN in ASP only. I'm happy to say I've got it all working and I'm very, very happy with the results. MSN Search was perhaps the trickiest one to get working, but actually very reliable and easy once I understood the format of the 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/1999/XMLSchema-instance" xmlns:xsd="http://www.w3.org/1999/XMLSchema">
<SOAP-ENV:Body>
<ns1:Search xmlns:ns1="http://schemas.microsoft.com/MSNSearch/2005/09/fex">
<Request>
<AppID xsi:type="xsd:string">AppID Goes Here</AppID>
<Query xsi:type="xsd:string">Example Query</Query>
<CultureInfo xsi:type="xsd:string">en-GB</CultureInfo>
<SafeSearch xsi:type="xsd:string">Off</SafeSearch>
<Requests>
<SourceRequest>
<Source xsi:type="xsd:string">Web</Source>
<Offset xsi:type="xsd:int">0</Offset>
<Count xsi:type="xsd:int">50</Count>
<ResultFields xsi:type="xsd:string">All</ResultFields>
</SourceRequest>
</Requests>
</Request>
</ns1:Search>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

My question related to the CultureInfo. Using "en-GB", I can retrieve results similar to doing a normal browser based search at msn.co.uk, which is exactly what I want.

However, what I am ultimately trying to achieve is 2 sets of results:

  1. UK results of pages from the UK only:
    Same as doing a normal search at www.msn.co.uk and selecting the tick box "Only from the United Kingdom"
  2. UK results, from the web:
    Same as doinga normal search at www.msn.co.uk without putting a tick in the UK only box.

Does that make sense?

I can achieve this happily with the other API's (Google, and Yahoo).
So I'm assuming I can do with with MSN by selecting the right CultureInfo?

Hope there's an answer - thanks for any input!

BSolveIT




Search Engine Optimisation (SEO) Specialists: http://www.bsolveit.com
BSolveIT

Staggering!? 4 Months later - and not a single follow up post from anyone? Not even a MS?

Good forum, eh? hehe um... yeah...ok.




Search Engine Optimisation (SEO) Specialists: http://www.bsolveit.com
BSolveIT

It appears that I missed this question back in January. My apologies.

The answer to your question is to use a combination of CultureInfo settings and query operators. For CultureInfo simply set the value to en-GB. To get UK only results, add the loc: operator to each query that you want to scope in this way. For Great Britain, the country/region code is gb, so the user's query would have loc:gb appended to it by your code for the "UK Only" case. You can use any type of UI selection mechanism you like to toggle between "UK Only" and "All Results", removing the query enhancement for the "All Results" case. Please let me know if you need additional information.




Jim Gordon, MSN Search Program Management
James Gordon

Hi James,

Many, many thanks - this is exactly what I needed to know. Better late than never, eh? hehe

I may have a few further questions shortly, as I'm upgrading my app. with AJAX - so stay alert.

Best.
Mark McNeece.




Search Engine Optimisation (SEO) Specialists: http://www.bsolveit.com
BSolveIT

I've seen some PHP code shared for this, does anyone care to share their ASP code? I hate to re-create the wheel.

Thanks!

Brian

B.Hutchison

Hi Brian

The following is a simple function I wrote in connection with the SOAP envelope I posted above (see my first post in this thread).  There must be a better solution, but this does work just fine:

Function MSNAPIResults(gQuery, gAppID, gOffset)
 If Trim(gQuery) = "" Then Exit Function

 Dim Qry
 Set Qry = Server.CreateObject("MSXML2.DOMDocument")
 Qry.load Server.MapPath("doMSNSearch.xml")
 Qry.selectSingleNode("//AppID").Text = gAppID
 Qry.selectSingleNode("//Query").Text = gQuery
 Qry.selectSingleNode("//Offset").Text = gOffset

 ' Post the SOAP message.
 Dim soap
 Set soap = Server.CreateObject("MSXML2.ServerXMLHTTP")
 soap.open "post", "
http://soap.search.msn.com/webservices.asmx", False
 soap.setRequestHeader "Content-Type", "text/xml"
 soap.setRequestHeader "SOAPAction", "Search"
 soap.send Qry ' Dump the results into an XML document.

 Dim Res
 Set Res = Server.CreateObject("MSXML2.DOMDocument")
 Res.loadXML (soap.responseText)

 set root = Res.documentElement
 set nodelist = root.getElementsByTagName("Result")

 ' Parse the XML document.
 Dim rTitle
 Dim rDesc
 Dim rURL
 c = 0
 Dim resArray
 ReDim resArray(49,2)

 For Each Node In Nodelist
  'retrieve the values
  rURL=""
  on error resume next
  rTitle = Node.childNodes.item(0).text
  rDesc = Node.childNodes.item(1).text
  rURL = Node.childNodes.item(2).text
  on error goto 0

  if Trim(rURL)<>"" then
   'its a result
   resArray(c, 0) = rTitle
   resArray(c, 1) = rDesc
   resArray(c, 2) = rURL
   c=c+1
  End If
 Next
 MSNAPIResults = resArray
End FUNCTION

I hope this helps? 

By the way, we use this, along with some other very similar functions for the Google Search API, and Yahoo Search API (REST) in an online ranking checker application.  The application isn't publicly available on our site as of course there's restrictions on how many automated queries you can run per day or month with an API key.

However, we've used very similar coding for our free keyword tool, and meta tag checker.  You can find them on our services page if you wanted to have a look.  Very simple tools indeed, but quite useful nonetheless.  We use them constantly every day as we're a search engine optimisation company.

Let me know how you get on?

- Mark. 




Search Engine Optimisation (SEO) Specialists: http://www.bsolveit.com
BSolveIT

Hi Mark,

Thank you kindly for the response. I'll let you know how it works out.

- Brian

B.Hutchison

No problem at all.

Slightly off topic, but I have a Google API function and soap packet for ASP also if it would be helpful? Also have the Yahoo API solution for ASP, which uses REST as opposed to SOAP, but the ASP is very similar.

I've also implemented them in ASP.Net 2.0 - which to be honest is much better. Let me know if you want me to post my source code?

Regards

Mark.




Search Engine Optimisation (SEO) Specialists: http://www.bsolveit.com
BSolveIT
Very interesting post bsolveit

Thank you!

i will be looking to do the same for my site: Search Engine Optimisation
take care!



www.viperchill.com
allsoppg
reply 9

You can use google to search for other answers

 

More Articles

• Is msn search api good for my purpose?
• Image search?
• XmlDataSource?
• Error while using MSN Search Web Service SDK
• adCenter - Java Example with axis?
• Offset and Count attributes of a SourceRequest
• Use msn api search with php
• MSN Search Web Service SDK Version 0.60 Now Available
• read am WSDL
• org.apache.axis.ConfigurationException: java.lang.IllegalStateExc...
Bookmark and Share
Welcome to Bokebb   New Update  
 

New Articles

• Client Error on search call
• MSN Search API implemented in ASP only
• spelling with CultureInfo = "de-De&
• MSN Search Developer Site Error.
• XmlDataSource?
• Accessing MSN Search Web Service from Perl
• Is msn search api good for my purpose?
• No results after first SourceResponse
• ApplicationId-Ip Specific
• 10,000 Search Query Limit
• Client found response content of type ''
• application ids
• How can i get Account and TOKEN for WEB
• "Client Error"
• Search is returning only 25 results

Hot Articles

• Using Search API to return adverts
• Msn Web services ?
• adCenter - Java Example with axis?
• ERRO
• How to change a CultureInfo and what eff
• Commercial usage
• Client Error on search call
• App Id
• Getting more than 250 results
• message
• Writing a Client in Java
• Client found response content of type ''
• Search News?
• Image search?
• Unattended Soap Installation

Recommend Articles

• Offset and Count attributes of a SourceR
• Using Search API to return adverts
• Search is returning only 25 results
• "Client Error"
• Web Server Extensions
• Showing non-english caracters in search
• MSN SEARCH SUCKS!
• Maximum number of site: arguments?
• Use asynchronous Search API
• What consitutes a query?
• Client found response content of type ''
• Many weeks no problems, now java.lang.Cl
• Getting more than 250 results
• live.com too slow
• Yahoo API