Creating a basic Web Service

This item was filled under [ .Net ]

A lot can be found on the internet regarding web services. Here am just gonna create a basic Web Service using ASP.Net/C#:

1. Run your Microsoft Visual Studio 2005

2. Create a new ASP.Net Web Service from File > New > Web Site > ASP.Net Web Service

3. Choose the language of your choice, enter a project name and press OK to proceed. (In my case, I have selected C# and created a project by the name of “EmService”)

4. In the code view, you can see alot of comments with C# code that is already written for you. A sample model HelloWorld is also created by default. Your code will look like:

using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Service : System.Web.Services.WebService
{
public Service () {

//Uncomment the following line if using designed components
//InitializeComponent();
}

[WebMethod]
public string HelloWorld() {
return "Hello World";
}

}

Guess what, your first Web Service is ready!

[WebMethod] attribute denotes that this method will be used by the clients, also this method has to be public in order for a client to use it.

5. To run your web service, simply right click your .asmx file from the “Solution Explorer” and select View in browser.

On the next screen, you will find the HelloWorld method to be listed under Service heading. If you click that, you will find all the SOAP and HTTP code produced.

6. Now, just press the Invoke button to see the result of the method named HelloWorld().

View MySQL Processes

This item was filled under [ MySQL ]

To view MySQL connections, query:

> SHOW PROCESSLIST;

The above query won’t be useful for web applications that use a single user for DB. However, “mytop” (a console based tool) can be used for monitoring the threads and performance of MySQL.

mytop

To learn more about mytop, click here.

Running ASP.Net on Windows Server 2003

This item was filled under [ .Net ]

I deployed an ASP.Net 2.0 application on Windows Server 2003 and was continously getting:

HTTP Error 404 - File or directory not found

I Googled for it, but couldn’t find much as most of the users faced the same issue deploying ASP.Net applications on Server 2003. Microsoft suggests re-checking ASP.Net installation, as it is not automatically installed with IIS 6.0 (on Windows Server 2003), see: http://support.microsoft.com/kb/332124

You can try performing the steps as stated on Microsoft website but if you still get the error, try out:

  • Stop IIS
  • Go to: \WINDOWS\Microsoft.NET\Framework\v2.0.x
  • Run aspnet_regiis.exe with parameter “-i”
  • Start IIS

    Run your web-page now. It worked well for me, let me know if it helps anyone else as well!

    Connection string for TeraData

    This item was filled under [ .Net ]

    To connect to a TeraData database, use the following connection string to create an OleDbConnection:

    Provider=TDOLEDB;Data Source=SERVERNAME;Persist Security Info=True;User ID=MyUser; Password=MyPassword;Session Mode=ANSI;

    MySQL: GROUP BY on DATETIME field

    This item was filled under [ MySQL ]

    Often webmasters want to sort out data on the basis of Dates when timestamp is stored as datetime in MySQL. To obtain the desired result, simply query:

    SELECT DATE_FORMAT(MyDate, '%d %M %Y') AS Date, COUNT(*) AS numRows FROM Table1 GROUP BY Date;

    Firefox: Smart keywords

    This item was filled under [ Uncategorized ]

    I just came across a very good feature of Firefox. Searching gets way too easier with FF. Suppose you visit IMDB.com alot and you have to search for movies. Right click on the Search box and select “Add a Keyword for this Search...” (sample keyword: ‘imdb’). Now next time you want to search something on IMDB.com, simply type “imdb <movie-name>” in your address bar, hit enter and you will be taken right to the result.

    *Read more about Smart keywords at: Mozilla.org

    Google: Keyword Tool

    This item was filled under [ SEO/Adsense ]

    Try out this tool to maximize your Adwords and/or Adsense performance.

    According to Google:
    “The Keyword Tool is a great way to find new keywords for your ad campaigns. For example, if you run a budget hotel, the Keyword Tool can suggest helpful related keywords like “hotel discounts” or “motels.” Adding these alternate terms to your ad group keyword lists can help you find new customers that you might otherwise have missed.” (Read more..)

    Jump to the Keyword Tool now: https://adwords.google.com/select/KeywordToolExternal

    The basics of MySQL Views

    This item was filled under [ MySQL ]

    Before diving into any technicalities, I would like to share a little about “Views”. What is a VIEW, what is the benefit of it?

    A view is a virtual or logical table composed of the result set of a query. Unlike ordinary tables (base tables) in a relational database, a view is not part of the physical schema: it is a dynamic, virtual table computed or collated from data in the database.

    Views can provide advantages over tables;

    • They can subset the data contained in a table
    • They can join and simplify multiple tables into a single virtual table
    • Views can act as aggregated tables, where aggregated data (sum, average etc.) are calculated and presented as part of the data
    • Views can hide the complexity of data, for example a view could appear as Sales2000 or Sales2001, transparently partitioning the actual underlying table
    • Views take very little space to store; only the definition is stored, not a copy of all the data they present
    • Depending on the SQL engine used, views can provide extra security.
    • Views can limit the exposure to which a table or tables are exposed to the outer world

    MySQL has added this feature in version 5.0.1. The basic operations on VIEW can be carried out through the following syntax:

    mysql> CREATE VIEW v AS SELECT * FROM table1;

    At the time of creation, the view definition is “frozen”. In simple words, any changes made to the table structure will not affect the VIEW result. For example, if you created a VIEW with 2 columns and added another column to the table structure, VIEW would be still giving you result with 2 columns. You may alter your VIEW by running the ALTER query:

    mysql> ALTER VIEW v AS SELECT * FROM table1;

    To drop a VIEW, run:

    mysql> DROP VIEW v;

    VIEW definitions are restricted to:

    • The SELECT statement cannot contain a subquery in the FROM clause
    • The SELECT statement cannot refer to system or user variables
    • The SELECT statement cannot refer to prepared statement parameters
    • Within a stored routine, the definition cannot refer to routine parameters or local variables
    • Any table or view referred to in the definition must exist. However, after a view has been created, it is possible to drop a table or view that the definition refers to. In this case, use of the view results in an error. To check a view definition for problems of this kind, use the CHECK TABLE statement
    • The definition cannot refer to a TEMPORARY table, and you cannot create a TEMPORARY view
    • The tables named in the view definition must already exist
    • You cannot associate a trigger with a view

    The article is an extract from: Wikipedia, MySQL 5.0 Reference Manual

    Executing PHP script from command line

    This item was filled under [ PHP ]

    Executing PHP scripts from command line is quite easy. You just need to know the right commands to execute your script. This procedure comes in handy while developing command line scripts.

    *NIX OS:
    /path/to/php -f /path/to/script.php

    Windows OS:
    X:\path\to\php.exe -f X:\path\to\script.php

    -f parses and executes <file>. For a list of command line parameters, visit:
    PHP: Using PHP from the command line

    Finding hostname from IP address

    This item was filled under [ PHP ]

    PHP has couple of network functions that come in handy. One of them is ‘gethostbyaddr‘. It returns the host name of the Internet host specified by ip_address (as defined by PHP.net).

    <?php
    echo gethostbyaddr("87.248.113.14");
    ?>

    Alternately, you can find it through the ‘ping’ command:

    > ping -a <ip>

    The ping command will not work in case the firewall is enabled on the host.

    Page 3 of 6«12345»...Last »