Wednesday, June 26, 2013

Webservice is Undefined Error (ASP.NET 4.0)

1. First step is to add reference to the web service using Ajax Script Manager:
 <asp:ScriptManager ID="ajaxManager" runat="server">  
     <Services>  
       <asp:ServiceReference Path="~/Services/ProductService.asmx" />  
     </Services>  
   </asp:ScriptManager>  
2. Secondly is to include the namespace in calling the webservice method
From
  ProductService.GetProducts(  
            function (data) {  
              $.each(data, function (index, elem) {  
                $("<option />")  
                 .text(elem.ProductName)  
                 .val(elem.ProductID)  
                 .appendTo("#products");  
              });  
            }  
       );  
To
  AccessingServerSideDataUsingClientScript.Services.ProductService.GetProducts(  
            function (data) {  
              $.each(data, function (index, elem) {  
                $("<option />")  
                 .text(elem.ProductName)  
                 .val(elem.ProductID)  
                 .appendTo("#products");  
              });  
            }  
       );  

Reference: http://omensblog.blogspot.com/2007/07/aspnet-ajax-web-service-calls-from.html
Greg

Tuesday, June 18, 2013

IsPalindrome generic function (C#)

Excerpt from .NET 4.0 Generic's Guide, there's an example on testing whether a string is Palindrome using a Stack object. I decided to create a a Queue based method. One additional tip was to reverse the Queue object.See code below:
Code:
public static bool IsPalindromic<T>(IEnumerable<T> inputSequence)   
       where T : IComparable  
     {  
       Queue<T> buffer = new Queue<T>();  
       foreach (T element in inputSequence)  
       {  
         buffer.Enqueue(element);  
         temp.Enqueue(element);  
       }  
       buffer = new Queue<T>(buffer.Reverse());  
       for (int i = 0; i < inputSequence.Count(); i++)  
       {  
         if (buffer.Dequeue().CompareTo(inputSequence.ElementAt(i)) == 0)  
         {  
           continue;  
         }  
         else  
           return false;  
       }  
       return true;  
     }  

Greg

OpenWebKitSharp Document Text similar to .NET WebBrowser.

Here's how you get the page source of a WebKitBrowser similar to DocumentText property of a .NET WebBrowser Control.
Code:
JSValue val = webkitBrowser.GetScriptManager.EvaluateScript("document.getElementsByTagName(\"html\")[0].outerHTML;");  
 if (val != null)  
 {  
    PageSource = val.ToString();  
 }  

Greg

Wednesday, June 12, 2013

Set attribute option element in OpenWebkitSharp

Here's how you set option element attribute using OpenWebKitSharp.
Code:
foreach (WebKit.DOMNode optionElement in nodeItem.ChildNodes)  
 {  
   if (searchInnerHtml && optionElement.TextContent.Equals(searchInnerString))  
   {  
       WebKit.InteropIDOMHTMLElement el =    
       (WebKit.Interop.IDOMHTMLElement)optionElement.GetWebKitObject();  
       el.setAttribute("selected", "selected");  
   }  
 }  

Retrieving the COM class factory for component with CLSID {D6BCA079-F61C-4E1E-B453-32A0477D02E3} Openwebkitsharp3.0

If you encountered an error while running OpenWebkitSharp in your workstation or production server with the specific details below:

Retrieving the COM class factory for component with CLSID {D6BCA079-F61C-4E1E-B453-32A0477D02E3} failed due to the following error: 800736b1 The application has failed to start because its side-by-side configuration is incorrect. Please see the application event log or use the command-line sxstrace.exe tool for more detail. (Exception from HRESULT: 0x800736B1).

The solution is to download Microsoft Visual C++ 2005 Service Pack 1 Redistributable Package MFC Security Update here: Visual C++ 2005 Service Pack 1 Redistributable and install it in your server/workstation.

Greg