Skip to content


WURFL .NET API

This is a totally unofficial release of WURFL API for .NET

Downloads:

Installation

Reference the binary files from your application. For ASP.NET web application, include this in your web.config file (system.web section):

<browsercaps>
<result type="Marg.Wurfl.WurflMobileCapabilities, Marg.Wurfl">
</result>
</browsercaps>

and of course, copy the Marg.Wurfl.dll file to your bin folder. You can also configure the logging subsystem. The API uses log4net logging library, so please check there for configuration. Mind you, there is a lot of debugging going on.  A sample is included in the sample web application.

Usage

This binary release was compiled with .NET Framework 2.0, but the could should be compatible with .NET Framework 1.1.
You can use ASP.NET server controls (from the System.Web.UI.MobileControls namespace) and you can query the device capabilities yourself. There are two options to that:

  1. Use Request.Browser object and query it (you can query for WURFL capabilities as well)
  2. Use WurflDeviceIndex object to query it. (cast Request.Browser object to WurflMobileCapabilities object)

Have fun!


20 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. Bharani says

    Hi,
    i saw your sample application and code. im trying to assign custom values for Request.browser object properties. how do i do that? can i get the code from anywhere?

  2. miha says

    Bharani, you need to replace the Request.Browser object with your own implementation in this case. You can check out the MargMobileCapabilities (or whatever the class is called :) ) and see how it is done. HTH, Miha.

  3. Bharani says

    hi miha.. im checking your code. its looke like rocket science to me :-) . im not that much skilled. can you please give me where i can find detailed usage of your implementation? How do i use it With MMIT? also as you have said how do i use it with request.browser or use WurflDeviceIndex object to query the capabilities? plz help me.

  4. miha says

    Bharani,

    1) if you want to use WurflMobileCapabilities for querying, just cast Request.Browser to it. There is a sample inside Sample2.aspx.cs:
    WurflMobileCapabilities mobileCaps = Request.Browser as WurflMobileCapabilities

    2) If you want to extend the “mapped” capabilities, you have to extend the WurflMobileCapabilities and provide properties on that. That way, you will be able to use
    Request.Browser.PropertyFromMIT. Note that not _all_ properties are mapped. Just the ones necessary. So, you can map them yourself, if need be.

    3) Alternatively, check out the mdbf (mdbf.codeplex.com), which is an aletrnative and you won’t have to deal with WURFL (as you get an updated browser.config file.

  5. Shaun Venus says

    I downloaded the src project from the wurlf api site and it has reference to a unit test project that is not included – is this something that you can make available so I can run some tests on the code?

    Thanks

    Shaun

  6. miha says

    Shaun, unfortunately not. That code is stashed away on some backup, so I don’t have it really handy. I wasn’t aware there was a reference to a test project though, so sorry for that.

  7. Alvin says

    is there a version of the dll that does not use log4net logging??? thank you in advance…

  8. miha says

    Alvin, no, there isn’t. But you can take the source and remove log4net from it, if you want.

    Regards,
    Miha.

  9. luigi says

    Hello, tried your API, but tell me one thing can I get deviceId with this? Or just check if certain device supports/requires something=

  10. miha says

    luigi, of course you can. This API is somewhat outdated, so you might want to check the ‘official’ .NET api. Available here: http://sourceforge.net/projects/wurfl/files/WURFL%20.NET%20API/1.0/WURFL.NET-1.0.zip/download

  11. luigi says

    Atleast your API was easier to implement, this ‘official’ is like a maze. Have you ever … used it?

  12. miha says

    No, not really. I guess Luca and the team are more focused on Java and PHP implementations… Anyhow, mdbf (http://mdbf.codeplex.com) is quite a good replacement for WURFL.

  13. ming says

    HttpListenerContext context = this._listener.GetContext();
    WurflMobileCapabilities cpas = new WurflMobileCapabilities(context );
    how could i use your API in a ConsoleApplication ?

  14. miha says

    ming, you can use it like so:
    // instantiate a WURFL downloader
    WurflDownloader downloader = new WurflDownloader();

    // load the wurfl index with pacthec and whatnot (as defined in the manifest file)
    // note: manifest location can also be an Uri, pointing to a website
    WurflIndex wurflIndex = downloader.LoadWurfl(manifestLocation);

    // from here on, you can query the WURFL database
    WurflDeviceIndex deviceIdx = wurflIndex.GetDeviceById(id_of_the_device);
    // or
    WurflDeviceIndex deviceIdx = wurflIndex.GetDeviceByUa(deviceUserAgentString)
    // or alternatively call GetDeviceByUaLoose (where it does loose matching and returns all of the matched devices with calculated match quality

    When you obtain WurflDeviceIndex, you can query the device capabilities
    string model = deviceIdx["model_name"].Value;

    Hope this helps. You need a working manifest file and wurfl.xml. Take a look at a sample web app for that.

  15. ming says

    your code which is very helpful works well in window xp, but the downloader is unable to LoadWurfl in windows 7.why …?

  16. miha says

    ming, I don’t have a clue. I don’t have windows 7 with developer tools, so you’re on your own here. I suggest you take sources, and run the application through the debugger.
    Alternatively, configure log4net and check the logs.

  17. ming says

    I got it.Programing in win7 need a configration.
    But ,i met a another question here : if I cannot got the uaString,how can i use wurflIndex.GetDeviceById(id_of_the_device);how can i get the id.

  18. miha says

    ming, that depends on you scenario. What exactly do you want to use WURFL API for? Device IDs are the ones as defined in the WURFL.XML file and you can get all of the devices in the databse through WurflIndex object. Have a look at it.

  19. ming says

    真心谢谢!

  20. miha says

    You’re welcome. :)



Some HTML is OK

or, reply to this post via trackback.



WP SlimStat