Share via


Open Gov… Dallas and Bing – done.

Well, that was easy. 

So easy that I spent the rest of the evening playing around with the UI of my App just for fun (yes, I consider that fun).

First, Dallas… I thought it would be a little challenging… after all, the idea of engaging services from a Data Marketplace itself just seems complex.  I was happily disappointed… if that makes sense.

Step one – had to get a Dallas account, which you can do by going here https://www.microsoft.com/windowsazure/dallas/ and then clicking on the link to the Developer portal.

Once you sign up, you’ll get your Dallas Account Key and your Unique User ID… you’ll need these later.

Once you get your account, you can browse the datasets and “subscribe” to them.  The idea is that one day you will pay for access to some of this data in little microtransactions (or other licensing agreements)… but everything I see up there is free for now.  I subscribed to:

  • AP Online
  • Data.gov 2006-2007 Crime Stats
  • NASA Mars Orbital Images (I have no idea why)

For this project, I want to work with the AP Online News Search – so I can pull up any new stories about the legislator I’m tracking… so I click on the AP Online Service… And it brings me to a very nice IU where you can test the service and copy the required HTTP request string. 

You ALSO have the option of just bypassing all of that HTTP/XML stuff, and download a C# class that wraps everything up nice and neat.  Definitely my style:

APOnlineDallas

Once you download it – you merely compile it into a .NET assembly, and you’re done.  Here’s the MASSIVE amount of code I needed to write to call into the AP Online datasource in Dallas and return a set of articles (links and all):

Dim d As New _ Microsoft.Dallas.Services.SearchNewsService(DallasAccountKey, DallasUserID) Dim newsItems As _ Generic.List(Of Microsoft.Dallas.Services.SearchNewsItem) = _ d.Invoke(searchTerm, "")

Two lines of code is all I need to get the data. 

From there, I added some code to populate a listview and to provide a preview in a webbrowser control.  Not much code, but mundane – so I won’t bore you with it here.

Next… BING .  I want to do a news search on Bing and bring that data back, too.

To get started, you need to go to the Bing Developer site, sign in, and get an AppID… you do that here: https://www.bing.com/developers/default.aspx 

Fairly easy and quick.

From there, you should download the Bing API SDK from here:

https://www.microsoft.com/downloads/details.aspx?FamilyId=0F513086-078B-47A8-A889-842DC93A69AB&displaylang=en

The Bing API has XML/REST, JSON, and SOAP interfaces… so there’s a lot to choose from.  Frankly, I didn’t want to write any code, so chose to copy as much from the SDK samples as I could.

I picked the VB.NET Sample Code for SOAP, as all of this REST work has made me long for some webservices. 

For my code – I created a webreference to the bing API at  https://api.bing.net/search.wsdl?Version=2.2

From there, I simply copied the code from the NewsSample.vb class – and modified it to populate a listview:

Dim request As New net.bing.api.SearchRequest With request .AppId = BingAppID .Query = SearchName '"msn moneycentral" .Sources = New net.bing.api.SourceType() _ {net.bing.api.SourceType.News} .Version = "2.0" .Market = "en-us" .Options = New net.bing.api.SearchOption() _ {net.bing.api.SearchOption.EnableHighlighting} .News = New net.bing.api.NewsRequest With .News .Offset = 0 .OffsetSpecified = True .SortBy = net.bing.api.NewsSortOption.Relevance .SortBySpecified = True End With End With

           Dim s As New net.bing.api.BingService() Dim response As _ net.bing.api.SearchResponse = s.Search(request)

             Dim result As net.bing.api.NewsResult

            For Each result In response.News.Results With result Dim lvi As New ListViewItem(.Title) lvi.Tag = result listViewBingNews.Items.Add(lvi) End With Next

The two bolded lines are really the only ones that do any work.. .the first few lines just set up a request, and then the bolded lines make the request to bing – which returns a collection of news items… and them I just pop them into a listview.

Total time… about another hour… not counting the random UI work I’ve been playing with throughout the evening.  Here’s how it looks now:

DotNetLegisTrackv2a

I also added some code to make it easier to enter the Sunlight API key, the Dallas key and user ID, and the Bing AppID… need to start thinking about how I’ll manage that for a real solution.  Best bet might be to host my own service interfaces in Windows Azure so the client app won’t need them (I’d authenticate another way).

Project stands at about 300 lines of code (most just simple declarations) – not including the downloaded class for Dallas or the REST classes I generated for Sunlight and GovTrack.  Maybe a total of 4-5 hours of work, including UI fiddling.

Frankly, writing these blog updates have been a lot more time consuming… :)

-Dan 

LegisTrack.zip

Comments

  • Anonymous
    February 12, 2010
    Just noticed that the reference to the WCF REST assemblies get lost in the zipped project. To make sure you can run it, follow these instructions: • Download and install the WCF REST Starter kit: http://msdn.microsoft.com/en-us/netframework/cc950529.aspx • Load the project in Visual Studio 2008/2010 • Click on the Project Menu, and choose “Add reference” • Navigate to the folder that holds the WCF REST assemblies/dlls – probably “Program Files (x86)Microsoft WCF RESTWCF REST Starter Kit Preview 2Assemblies” • Select all 3 DLLs and click OK Should work from there. -Dan