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:
- Use Request.Browser object and query it (you can query for WURFL capabilities as well)
- Use WurflDeviceIndex object to query it. (cast Request.Browser object to WurflMobileCapabilities object)
Have fun!
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?
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.
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.
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.
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
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.
is there a version of the dll that does not use log4net logging??? thank you in advance…
Alvin, no, there isn’t. But you can take the source and remove log4net from it, if you want.
Regards,
Miha.
Hello, tried your API, but tell me one thing can I get deviceId with this? Or just check if certain device supports/requires something=
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
Atleast your API was easier to implement, this ‘official’ is like a maze. Have you ever … used it?
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.
HttpListenerContext context = this._listener.GetContext();
WurflMobileCapabilities cpas = new WurflMobileCapabilities(context );
how could i use your API in a ConsoleApplication ?
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.
your code which is very helpful works well in window xp, but the downloader is unable to LoadWurfl in windows 7.why …?
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.
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.
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.
真心谢谢!
You’re welcome.