Pages

Thursday, August 30, 2012

Fix for 401 errors when getting data via C# webservice for AJAX

Application wide:
In your web.config, add the following lines.
<system.web>
  <webServices>
    <protocols>
      <add name="HttpGet" />
      <add name="HttpPost" />
    </protocols>
  </webServices>
</system.web>

Code level:
Add the following before your webservice method.
[ScriptMethod(UseHttpGet = true)]

Example:
[ScriptMethod(UseHttpGet = true)]
[WebMethod(Description = "webservice description.")]
public List GetItems()
{
  // more codes
}

Friday, August 3, 2012

Get the quotient using addition and subtraction only.

private string getQuotient(int dividend, int divisor)
{
  string result = "";
  int wholeNumber = 0;
            
  // loop until the dividend will result a positive integer
  while ((dividend > 0) && (dividend >= divisor))
  {
    dividend -= divisor;
    wholeNumber++;
  }

  result = wholeNumber.ToString() + " r. " + dividend.ToString();
            
  return result;
}