### Initialize and Configure WURFL Client Source: https://github.com/wurfl/wurfl-microservice-client-dotnet/blob/master/README.md Demonstrates how to instantiate the WpcClient and define the specific device capabilities to be retrieved during detection. ```csharp protected void Application_Start() { WpcClient client = WpcClient.Create("localhost", "8081"); var requestedCapabilities = new string[]{ "brand_name", "model_name", "is_mobile", "is_tablet", "is_smartphone" }; client.SetRequestedCapabilities(requestedCapabilities); } ``` -------------------------------- ### Create and Configure WURFL Client Connection Source: https://context7.com/wurfl/wurfl-microservice-client-dotnet/llms.txt Demonstrates how to initialize the WmClient, configure LRU caching, and retrieve server metadata. This is the foundational step for establishing communication with the WURFL Microservice API. ```csharp using Wmclient; try { // Create client with scheme, host, port, and optional base URI WmClient client = WmClient.Create("http", "localhost", "8080", ""); // Enable caching with a maximum of 100,000 entries client.SetCacheSize(100000); // Retrieve server information JSONInfoData info = client.GetInfo(); Console.WriteLine("WURFL API version: " + info.Wurfl_api_version); Console.WriteLine("WM server version: " + info.Wm_version); Console.WriteLine("WURFL file info: " + info.Wurfl_info); Console.WriteLine("Static capabilities count: " + info.Static_caps.Length); Console.WriteLine("Virtual capabilities count: " + info.Virtual_caps.Length); // Clean up resources when done client.DestroyConnection(); } catch (WmException e) { Console.WriteLine("Connection error: " + e.Message); } ``` -------------------------------- ### Perform Device Lookup using HTTP Headers Source: https://github.com/wurfl/wurfl-microservice-client-dotnet/blob/master/README.md Illustrates how to perform device detection by manually constructing a dictionary of HTTP headers and passing them to the LookupHeaders method. ```csharp var headers = new Dictionary(); headers.Add("Content-Type", "application/json"); headers.Add("Accept-Encoding", "gzip, deflate"); headers.Add("User-Agent", "Opera/9.80 (Android; Opera Mini/51.0.2254/184.121; U; en) Presto/2.12.423 Version/12.16"); // Perform a device detection calling WM server API passing the whole request headers JSONDeviceData device = client.LookupHeaders(headers); ``` -------------------------------- ### Query Operating Systems and Versions in .NET Source: https://context7.com/wurfl/wurfl-microservice-client-dotnet/llms.txt Fetches all available operating system names and their corresponding versions from the WURFL database. This allows for granular filtering of devices based on OS platform. ```csharp WmClient client = WmClient.Create("http", "localhost", "8080", ""); try { string[] operatingSystems = client.GetAllOSes(); Array.Sort(operatingSystems); Console.WriteLine($"Total operating systems: {operatingSystems.Length}"); foreach (string os in operatingSystems) { Console.WriteLine($" - {os}"); } string osName = "Android"; string[] androidVersions = client.GetAllVersionsForOS(osName); Array.Sort(androidVersions); Console.WriteLine($"\n{osName} versions ({androidVersions.Length} total):"); foreach (string version in androidVersions) { Console.WriteLine($" - {version}"); } } catch (WmException e) { Console.WriteLine("Error: " + e.Message); } finally { client.DestroyConnection(); } ``` -------------------------------- ### Perform Device Detection via User-Agent Source: https://context7.com/wurfl/wurfl-microservice-client-dotnet/llms.txt Illustrates the use of the LookupUserAgent method to identify device characteristics from a raw user-agent string. Includes error handling and access to the returned device capability data. ```csharp WmClient client = WmClient.Create("http", "localhost", "8080", ""); client.SetCacheSize(50000); var requestedCaps = new string[] { "brand_name", "model_name", "is_smartphone", "form_factor" }; client.SetRequestedCapabilities(requestedCaps); try { // Mobile user-agent example string userAgent = "Mozilla/5.0 (iPhone; CPU iPhone OS 15_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.0 Mobile/15E148 Safari/604.1"; JSONDeviceData device = client.LookupUserAgent(userAgent); // Access detected capabilities Console.WriteLine("WURFL ID: " + device.Capabilities["wurfl_id"]); Console.WriteLine("Brand: " + device.Capabilities["brand_name"]); Console.WriteLine("Model: " + device.Capabilities["model_name"]); Console.WriteLine("Form Factor: " + device.Capabilities["form_factor"]); Console.WriteLine("Is Smartphone: " + device.Capabilities["is_smartphone"]); // Check for errors if (!string.IsNullOrEmpty(device.Error)) { Console.WriteLine("Detection error: " + device.Error); } } catch (WmException e) { Console.WriteLine("Lookup failed: " + e.Message); } finally { client.DestroyConnection(); } ``` -------------------------------- ### Perform Device Lookup from HTTP Request Source: https://github.com/wurfl/wurfl-microservice-client-dotnet/blob/master/README.md Shows how to use the initialized client to perform device detection within an ASP.NET MVC controller by passing the current HTTP request. ```csharp public ActionResult MyControllerMethod() { var req = System.Web.HttpContext.Current.Request; JSONDeviceData device = client.LookupRequest(req); [...] } ``` -------------------------------- ### LookupHeaders - Detecting Device by HTTP Headers Dictionary Source: https://context7.com/wurfl/wurfl-microservice-client-dotnet/llms.txt The LookupHeaders method performs device detection using a dictionary of HTTP headers. This approach provides more accurate detection by utilizing multiple device identification headers beyond just the User-Agent. ```APIDOC ## POST /wurfl/lookupHeaders ### Description Performs device detection using a dictionary of HTTP headers. ### Method POST ### Endpoint /wurfl/lookupHeaders ### Parameters #### Request Body - **headers** (Dictionary) - Required - A dictionary containing HTTP headers for device detection. ### Request Example ```json { "headers": { "User-Agent": "Opera/9.80 (Android; Opera Mini/51.0.2254/184.121; U; en) Presto/2.12.423 Version/12.16", "Accept": "text/html, application/xml;q=0.9, application/xhtml+xml, */*;q=0.1", "Accept-Language": "en", "Accept-Encoding": "gzip, deflate", "X-Forwarded-For": "110.54.224.195, 82.145.210.235", "X-Operamini-Phone": "Android #", "X-Operamini-Phone-Ua": "Mozilla/5.0 (Linux; Android 8.1.0; SM-J610G Build/M1AJQ; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/69.0.3497.100 Mobile Safari/537.36", "Device-Stock-Ua": "Mozilla/5.0 (Linux; Android 8.1.0; SM-J610G Build/M1AJQ; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/69.0.3497.100 Mobile Safari/537.36" } } ``` ### Response #### Success Response (200) - **capabilities** (Dictionary) - A dictionary containing the detected device capabilities. #### Response Example ```json { "capabilities": { "wurfl_id": "generic_android_generic", "brand_name": "Generic", "model_name": "Android Generic", "is_smartphone": "true", "form_factor": "Smartphone", "device_os": "Android", "device_os_version": "8.1" } } ``` ``` -------------------------------- ### Filter Requested Device Capabilities Source: https://context7.com/wurfl/wurfl-microservice-client-dotnet/llms.txt Shows how to restrict the device attributes returned by the API to improve performance and reduce payload size. Supports setting static and virtual capabilities individually or in bulk. ```csharp WmClient client = WmClient.Create("http", "localhost", "8080", ""); // Option 1: Set both static and virtual capabilities at once var allCapabilities = new string[] { "brand_name", "model_name", "is_mobile", "is_tablet", "is_smartphone", "form_factor", "device_os", "device_os_version" }; client.SetRequestedCapabilities(allCapabilities); // Option 2: Set static and virtual capabilities separately var staticCaps = new string[] { "brand_name", "model_name", "device_os" }; var virtualCaps = new string[] { "is_smartphone", "form_factor" }; client.SetRequestedStaticCapabilities(staticCaps); client.SetRequestedVirtualCapabilities(virtualCaps); // Check if a capability exists before using it if (client.HasStaticCapability("brand_name")) { Console.WriteLine("brand_name capability is available"); } if (client.HasVirtualCapability("is_smartphone")) { Console.WriteLine("is_smartphone virtual capability is available"); } // Reset to return all capabilities client.SetRequestedCapabilities(null); ``` -------------------------------- ### Handle WURFL Errors with WmException (.NET) Source: https://context7.com/wurfl/wurfl-microservice-client-dotnet/llms.txt This code illustrates how to handle WURFL-specific exceptions (`WmException`) that can occur due to connection failures, invalid requests, or server-side issues. It shows checking for inner exceptions for more detailed error analysis. ```csharp try { // Attempt to connect to a non-existent server WmClient client = WmClient.Create("http", "invalid-host", "9999", ""); JSONDeviceData device = client.LookupUserAgent("Mozilla/5.0"); Console.WriteLine("Device: " + device.Capabilities["brand_name"]); } catch (WmException e) { // Handle WURFL-specific errors Console.WriteLine("WURFL Error: " + e.Message); // Check for inner exception (network, HTTP, etc.) if (e.InnerException != null) { Console.WriteLine("Caused by: " + e.InnerException.GetType().Name); Console.WriteLine("Details: " + e.InnerException.Message); } } // Example: Handling invalid manufacturer lookup WmClient validClient = null; try { validClient = WmClient.Create("http", "localhost", "8080", ""); // This will throw WmException if manufacturer doesn't exist JSONModelMktName[] devices = validClient.GetAllDevicesForMake("NonExistentBrand"); } catch (WmException e) { Console.WriteLine("Lookup error: " + e.Message); } finally { validClient?.DestroyConnection(); } ``` -------------------------------- ### List Device Manufacturers and Models in .NET Source: https://context7.com/wurfl/wurfl-microservice-client-dotnet/llms.txt Retrieves a list of all device manufacturers from the WURFL database and fetches specific device models for a given manufacturer. Useful for building UI filters or inventory lists. ```csharp WmClient client = WmClient.Create("http", "localhost", "8080", ""); try { string[] makes = client.GetAllDeviceMakes(); Console.WriteLine($"Total manufacturers: {makes.Length}"); Array.Sort(makes); for (int i = 0; i < Math.Min(10, makes.Length); i++) { Console.WriteLine($" - {makes[i]}"); } string manufacturer = "Samsung"; JSONModelMktName[] samsungDevices = client.GetAllDevicesForMake(manufacturer); Console.WriteLine($"\n{manufacturer} devices: {samsungDevices.Length}"); for (int i = 0; i < Math.Min(10, samsungDevices.Length); i++) { var device = samsungDevices[i]; string marketingName = !string.IsNullOrEmpty(device.Marketing_Name) ? $" ({device.Marketing_Name})" : ""; Console.WriteLine($" - {device.Model_Name}{marketingName}"); } } catch (WmException e) { Console.WriteLine("Error: " + e.Message); } finally { client.DestroyConnection(); } ``` -------------------------------- ### LookupRequest - Detecting Device from ASP.NET HttpRequest Source: https://context7.com/wurfl/wurfl-microservice-client-dotnet/llms.txt The LookupRequest method performs device detection directly from an ASP.NET HttpRequest object. This is the recommended method for web applications as it automatically extracts relevant headers. ```APIDOC ## POST /wurfl/lookupRequest ### Description Performs device detection directly from an ASP.NET HttpRequest object. ### Method POST ### Endpoint /wurfl/lookupRequest ### Parameters #### Request Body - **request** (HttpRequest) - Required - The ASP.NET HttpRequest object. ### Request Example *(This endpoint operates on the current HttpRequest context in ASP.NET, so a direct JSON body example is not applicable. The request is implicitly the current HTTP request.)* ### Response #### Success Response (200) - **capabilities** (Dictionary) - A dictionary containing the detected device capabilities. #### Response Example ```json { "capabilities": { "wurfl_id": "generic_android_generic", "brand_name": "Generic", "model_name": "Android Generic", "is_mobile": "true", "is_tablet": "false", "is_smartphone": "true", "form_factor": "Smartphone" } } ``` ``` -------------------------------- ### Retrieve WURFL Microservice Server Information (.NET) Source: https://context7.com/wurfl/wurfl-microservice-client-dotnet/llms.txt This snippet demonstrates how to retrieve metadata from the WURFL Microservice server, including API version, WURFL file details, and available capabilities. It requires the WmClient class and handles potential WURFL exceptions. ```csharp WmClient client = WmClient.Create("http", "localhost", "8080", ""); try { JSONInfoData info = client.GetInfo(); Console.WriteLine("=== WURFL Microservice Server Info ==="); Console.WriteLine($"WM Server Version: {info.Wm_version}"); Console.WriteLine($"WURFL API Version: {info.Wurfl_api_version}"); Console.WriteLine($"WURFL File Info: {info.Wurfl_info}"); Console.WriteLine($"Last WURFL Load Time: {info.Ltime}"); Console.WriteLine($"\nStatic Capabilities ({info.Static_caps.Length}):"); Array.Sort(info.Static_caps); foreach (string cap in info.Static_caps) { Console.WriteLine($" - {cap}"); } Console.WriteLine($"\nVirtual Capabilities ({info.Virtual_caps.Length}):"); Array.Sort(info.Virtual_caps); foreach (string vcap in info.Virtual_caps) { Console.WriteLine($" - {vcap}"); } Console.WriteLine($"\nImportant Headers for Detection ({info.Important_headers.Length}):"); foreach (string header in info.Important_headers) { Console.WriteLine($" - {header}"); } // Client API version Console.WriteLine($"\nClient API Version: {client.GetApiVersion()}"); } catch (WmException e) { Console.WriteLine("Failed to get server info: " + e.Message); } finally { client.DestroyConnection(); } ``` -------------------------------- ### LookupHeaders - Detect Device by HTTP Headers Dictionary in C# Source: https://context7.com/wurfl/wurfl-microservice-client-dotnet/llms.txt Performs device detection using a dictionary of HTTP headers. This method is useful when you have access to raw HTTP headers and want to perform device detection outside of a web request context. It requires the WURFL client to be initialized and capabilities to be set. ```csharp WmClient client = WmClient.Create("http", "localhost", "8080", ""); client.SetCacheSize(100000); var requestedCaps = new string[] { "brand_name", "model_name", "is_smartphone", "form_factor", "device_os", "device_os_version" }; client.SetRequestedCapabilities(requestedCaps); try { // Build headers dictionary (header names are case-insensitive) var headers = new Dictionary(); headers.Add("User-Agent", "Opera/9.80 (Android; Opera Mini/51.0.2254/184.121; U; en) Presto/2.12.423 Version/12.16"); headers.Add("Accept", "text/html, application/xml;q=0.9, application/xhtml+xml, */*;q=0.1"); headers.Add("Accept-Language", "en"); headers.Add("Accept-Encoding", "gzip, deflate"); headers.Add("X-Forwarded-For", "110.54.224.195, 82.145.210.235"); headers.Add("X-Operamini-Phone", "Android #"); headers.Add("X-Operamini-Phone-Ua", "Mozilla/5.0 (Linux; Android 8.1.0; SM-J610G Build/M1AJQ; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/69.0.3497.100 Mobile Safari/537.36"); headers.Add("Device-Stock-Ua", "Mozilla/5.0 (Linux; Android 8.1.0; SM-J610G Build/M1AJQ; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/69.0.3497.100 Mobile Safari/537.36"); JSONDeviceData device = client.LookupHeaders(headers); Console.WriteLine("WURFL ID: " + device.Capabilities["wurfl_id"]); Console.WriteLine("Brand: " + device.Capabilities["brand_name"]); Console.WriteLine("Model: " + device.Capabilities["model_name"]); Console.WriteLine("OS: " + device.Capabilities["device_os"] + " " + device.Capabilities["device_os_version"]); Console.WriteLine("Form Factor: " + device.Capabilities["form_factor"]); if (device.Capabilities["is_smartphone"] == "true") { Console.WriteLine("Device is a smartphone"); } } catch (WmException e) { Console.WriteLine("Lookup failed: " + e.Message); } finally { client.DestroyConnection(); } ``` -------------------------------- ### LookupRequest - Detect Device from ASP.NET HttpRequest in C# Source: https://context7.com/wurfl/wurfl-microservice-client-dotnet/llms.txt Performs device detection directly from an ASP.NET `HttpRequest` object. This is the recommended method for web applications as it automatically extracts relevant headers from the request. It requires the WURFL client to be initialized globally and capabilities to be set. ```csharp // In ASP.NET Framework Global.asax using Wmclient; public class Global : System.Web.HttpApplication { public static WmClient WurflClient { get; private set; } protected void Application_Start() { WurflClient = WmClient.Create("http", "localhost", "8080", ""); WurflClient.SetCacheSize(100000); var requestedCaps = new string[] { "brand_name", "model_name", "is_mobile", "is_tablet", "is_smartphone", "form_factor" }; WurflClient.SetRequestedCapabilities(requestedCaps); } protected void Application_End() { WurflClient?.DestroyConnection(); } } // In ASP.NET MVC Controller public class DeviceController : Controller { public ActionResult DetectDevice() { try { var request = System.Web.HttpContext.Current.Request; JSONDeviceData device = Global.WurflClient.LookupRequest(request); ViewBag.WurflId = device.Capabilities["wurfl_id"]; ViewBag.Brand = device.Capabilities["brand_name"]; ViewBag.Model = device.Capabilities["model_name"]; ViewBag.IsMobile = device.Capabilities["is_mobile"] == "true"; ViewBag.IsTablet = device.Capabilities["is_tablet"] == "true"; ViewBag.FormFactor = device.Capabilities["form_factor"]; return View(); } catch (WmException e) { ViewBag.Error = e.Message; return View("Error"); } } } ``` -------------------------------- ### Lookup Device Data by WURFL ID in .NET Source: https://context7.com/wurfl/wurfl-microservice-client-dotnet/llms.txt Retrieves specific device capabilities using a known WURFL device identifier. This method requires the client to be configured with requested capabilities and handles potential connection exceptions. ```csharp WmClient client = WmClient.Create("http", "localhost", "8080", ""); client.SetCacheSize(20000); var requestedCaps = new string[] { "brand_name", "model_name", "marketing_name", "resolution_width", "resolution_height", "device_os" }; client.SetRequestedCapabilities(requestedCaps); try { string wurflId = "apple_iphone_ver14_subua"; JSONDeviceData device = client.LookupDeviceID(wurflId); Console.WriteLine("Device found for WURFL ID: " + wurflId); Console.WriteLine("Brand: " + device.Capabilities["brand_name"]); Console.WriteLine("Model: " + device.Capabilities["model_name"]); Console.WriteLine("OS: " + device.Capabilities["device_os"]); foreach (var cap in device.Capabilities) { Console.WriteLine($" {cap.Key}: {cap.Value}"); } } catch (WmException e) { Console.WriteLine("Device lookup failed: " + e.Message); } finally { client.DestroyConnection(); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.