MSN Search Snippet
Last changed: -213.199.128.155

.

This sample shows how to call the MSN-LIVE search API from F# interactive.

Use wsdl.exe to generate a C# wrapper for the service:

  C:\james\dev\temp> wsdl http://soap.search.msn.com/webservices.asmx?wsdl
  wsdl http://soap.search.msn.com/webservices.asmx?wsdl
  Microsoft (R) Web Services Description Language Utility
  [Microsoft (R) .NET Framework, Version 2.0.50727.42]
  Copyright (C) Microsoft Corporation. All rights reserved.
  Writing file 'C:\james\dev\temp\MSNSearchService.cs'.

which can be compiled into a dll

  C:\james\dev\temp>csc /target:library MSNSearchService.cs 
  csc /target:library MSNSearchService.cs 
  Microsoft (R) Visual C# 2005 Compiler version 8.00.50727.42
  for Microsoft (R) Windows (R) 2005 Framework version 2.0.50727
  Copyright (C) Microsoft Corporation 2001-2005. All rights reserved.

Then in a fsi.exe session:

  #r "MSNSearchService.dll";;
  let msn = new MSNSearchService()


  let src = new SourceRequest()
  do  src.Source <- SourceType.Web
  do  src.ResultFields <- ResultFieldMask.All
  do  src.Count  <- 50   // max 50
  do  src.Offset <- 0    // max 250 - Count


  let req = new SearchRequest()
  do  req.Query <- "fsharp"
  do  req.Requests <- [| src |]
  do  req.CultureInfo <- "en-US"
  do  req.AppID <- "YOUR-APPID-HERE"
  // Get AppId from: http://search.msn.com/developer/  (about 2 minutes)


  let resp = msn.Search(req)


  let fix s = match s with null -> "" | _ -> s


  let rs  = resp.Responses.[0].Results
  let res = resp.Responses.[0].Results |> IEnumerable.to_list
  do  List.iteri (fun i (r:Result) -> printf "%2d. %s\n" i (fix r.Description)) res

You will need to get an appId, but thats very quick, see: http://search.msn.com/developer/

References:

- http://msdn.microsoft.com/live/

- http://msdn.microsoft.com/live/gettingstarted/

- http://msdn.microsoft.com/live/gettingstarted/searchstart/default.aspx

- http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msn_search_web_service_sdk/html/introducingthemsnsearchwebservice.asp