Using the MDT database from a web service without writing code


One of the new features in the .NET Framework 3.5 SP1 is ADO.NET Data Services.  This enables you to expose the contents of a data source, e.g. a SQL Server database, through something that looks roughly like an RSS feed, accessed in a similar manner to a web service.  That’s nice but why do you care as an IT pro?  Well, it’s a convenient way of making the contents of the MDT database available to programs or scripts without forcing them to use ADO to access SQL Server directly.


The best part of ADO.NET Data Services:  You really don’t need to write any code.  Just walk through a few Visual Studio 2008 wizards and you’re done – almost.  There are two lines of code that I added, one to day that all the selected tables and rows can be accessed read-only, and a second that generates detailed errors if something doesn’t work.  The basic process is described at http://msdn.microsoft.com/en-us/data/cc745957.aspx.  (So I lied – you have to write two lines of code.)


The harder part of this is deploying the resulting ADO.NET Data Services project to an IIS server.  You need to have .NET 3.5 SP1 installed, then IIS and ASP.NET need to be installed.  You might need to run “ServiceModelReg.exe –i” to get the ADO.NET Data Services and WCF logic registered in IIS, see http://msdn.microsoft.com/en-us/library/ms732012.aspx for details.  You will definitely need to edit the database connection string in the Web.Config file to point to your server (and optionally the instance) as well as the database (Initial Catalog) that needs to be used.  And you might need to grant access to SQL Server, the database, and the database tables and views.  (See http://msdn.microsoft.com/en-us/library/ms998320.aspx if SQL Server is on the same machine.)  Really, it’s not that bad :-)


The actual ADO.NET Data Services files need to all be dropped in a directory.  After doing this, set up an application in IIS that points to this directory.  At that point, if everything is set up right, you should be able to access the the web service via a browser.  To test it out, try a URL like this:


http://yourserver/YourApplicationName/MDTDatabase.svc


If that gives you a list of objects available in the database (you might need to tell IE not to display the result in RSS Reader view to see the real contents – in IE8, that’s configured on the “Content” tab from the “Feeds and Slices” settings dialog), you know at least IIS, .NET, and ADO.NET are fine.  Then try a more specific URL to request all the computer records:


http://yourserver/YourApplicationName/MDTDatabase.svc/ComputerIdentity


That should result in something that looks like this:


image


 


Yes, kind of weird looking, but pretty easy to consume in a script.  So that’s the next step – making use of this data.  More on that in the next posting.


The full solution (Visual Studio project, source, binaries, etc.) is attached.

MDTDatabase.zip


Comments (5)

  1. help says:

    Having issue deploying application after selecting the Role. whatever i assign to the Role, its not deploying.. please help. am i missing anything..

  2. Saulius M says:

    IS there onlu me out there, who gets error "invalid column name 'OSRoleService'" when trying to view http://myserver/MyApplicationName/MDTDatabase.svc/MakeModelSettings

  3. skullicious says:

    Hey!

    I cannot follow the
    http://msdn.microsoft.com/en-us/data/cc745957.aspx link. Is it broken?

    Thanks!

  4. showbox says:

    Thanks for the great info. I really loved this. I would like to apprentice at the same time as you amend your web site, how could i subscribe for a blog site?
    For more info on showbox please refer below sites:
    http://showboxandroids.com/showbox-apk/
    http://showboxappandroid.com/
    Latest version of Showbox App download for all android smart phones and tablets.
    http://movieboxappdownloads.com/ – It’s just 2 MB file you can easily get it on your android device without much trouble. Showbox app was well designed application for android to watch movies and TV shows, Cartoons and many more such things on your smartphone.
    For showbox on iOS (iPhone/iPad), please read below articles:
    http://showboxappk.com/showbox-for-ipad-download/
    http://showboxappk.com/showbox-for-iphone/
    Showbox for PC articles:
    http://showboxandroids.com/showbox-for-pc/
    http://showboxappandroid.com/showbox-for-pc-download/
    http://showboxforpcs.com/
    There are countless for PC clients as it is essentially easy to understand, simple to introduce, gives continuous administration, effectively reasonable. it is accessible at completely free of expense i.e., there will be no establishment charges and after establishment
    it doesn’t charge cash for watching films and recordings. Not simply watching, it likewise offers alternative to download recordings and motion pictures. The accompanying are the strides that are to be taken after to introduce Showbox application on Android.
    The above all else thing to be done is, go to the Security Settings on your Android telephone, Scroll down and tap on ‘Obscure sources’.

  5. aw says:

    hai, I just want to tell you that I am just very new to blogs and seriously loved this website. More than likely I’m planning to bookmark your blog post .
    You amazingly come with really good posts. Thanks a lot for sharing your blog Microsoft.

    http://www.lokerjobindo.com/search/label/Loker%20Daerah%20Aceh
    http://www.lokerjobindo.com/search/label/Loker%20Daerah%20Bali
    http://www.lokerjobindo.com/search/label/Loker%20Daerah%20Balikpapan
    http://www.lokerjobindo.com/search/label/Loker%20Daerah%20Bandung
    http://www.lokerjobindo.com/search/label/Loker%20Daerah%20Banjarmasin
    http://www.lokerjobindo.com/search/label/Loker%20Daerah%20Banten
    http://www.lokerjobindo.com/search/label/Loker%20Daerah%20Batam
    http://www.lokerjobindo.com/search/label/Loker%20Daerah%20Bekasi
    http://www.lokerjobindo.com/search/label/Loker%20Daerah%20Bengkulu
    http://www.lokerjobindo.com/search/label/Loker%20Daerah%20Bogor
    http://www.lokerjobindo.com/search/label/Loker%20Daerah%20Bontang
    http://www.lokerjobindo.com/search/label/Loker%20Daerah%20Cianjur
    http://www.lokerjobindo.com/search/label/Loker%20Daerah%20Cikarang
    http://www.lokerjobindo.com/search/label/Loker%20Daerah%20Cilegon
    http://www.lokerjobindo.com/search/label/Loker%20Daerah%20Cirebon
    http://www.lokerjobindo.com/search/label/Loker%20Daerah%20Denpasar
    http://www.lokerjobindo.com/search/label/Loker%20Daerah%20Jakarta
    http://www.lokerjobindo.com/search/label/Loker%20Daerah%20Jambi
    http://www.lokerjobindo.com/search/label/Loker%20Daerah%20Jember
    http://www.lokerjobindo.com/search/label/Loker%20Daerah%20Karawang
    http://www.lokerjobindo.com/search/label/Loker%20Daerah%20Kendal
    http://www.lokerjobindo.com/search/label/Loker%20Daerah%20Kudus
    http://www.lokerjobindo.com/search/label/Loker%20Daerah%20Kupang
    http://www.lokerjobindo.com/search/label/Loker%20Daerah%20Lampung
    http://www.lokerjobindo.com/search/label/Loker%20Daerah%20Madiun
    http://www.lokerjobindo.com/search/label/Loker%20Daerah%20Makasar
    http://www.lokerjobindo.com/search/label/Loker%20Daerah%20Malang
    http://www.lokerjobindo.com/search/label/Loker%20Daerah%20Maluku
    http://www.lokerjobindo.com/search/label/Loker%20Daerah%20Manado
    http://www.lokerjobindo.com/search/label/Loker%20Daerah%20Medan
    http://www.lokerjobindo.com/search/label/Loker%20Daerah%20NTT
    http://www.lokerjobindo.com/search/label/Loker%20Daerah%20Padang