Monday, February 28, 2011

asp:ScriptManager - Unknown server tag

Below are the links I followed in order to resolve 
the mistery of the error
 "UNKNOWN SERVER TAG"  -  related to asp:ScriptManager 

 

http://localhost/TestWeb/SimpleWebService.aspx

Server Error in '/TestWeb' Application.


Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.

Parser Error Message: Unknown server tag 'asp:ScriptManager'.

Source Error:
 

Version Information: Microsoft .NET Framework Version:2.0.50727.3053; ASP.NET Version:2.0.50727.3053 
 
Line 42:         form id="Form1" runat="server"
Line 43: asp:ScriptManager runat="server" ID="scriptManager" Line 44: Services Line 45:  asp:ServiceReference path="SimpleWebService.asmx"
 
 

Professional ASP.NET 2.0 AJAX
Matt Gibbs, Dan Wahlin
ISBN: 978-0-470-10962-5
Paperback
336 pages
June 2007
 
http://www.wrox.com/WileyCDA/WroxTitle/productCd-0470109629.html

Professional-ASP-NET-2-0-AJAX - source code DOWNLOAD  

I took the Web.Config from the chapter 4  ( or 5 ? )  and everything was OK ,
  problem solved !

 

~ ~ ~ 

Ajaxed Part II. Server Side AJAX
http://thejoyofcode.com/Ajaxed_Part_II._Server_Side_AJAX.aspx


How to set path to the scriptreference in ScriptManager

http://www.dotnetspider.com/forum/145097-how-set-path-scriptreference-ScriptManager.aspx

http://www.asp.net/ajax/videos/how-do-i-make-client-side-network-callbacks-with-aspnet-ajax

 How To Consume Web Services Using AJAX and ASP.NET 3.5

http://visualstudiomagazine.com/articles/2007/09/01/consuming-remote-web-services-with-aspnet-ajax.aspx 

A beginner’s guide for consuming a WCF service in JavaScript using ASP.NET AJAX

Using the ScriptManager

Calling Web Services from Client Script

http://msdn.microsoft.com/en-us/library/system.web.ui.scriptmanager.aspx

MicrosoftAjax.js ,ScriptPath , ScriptManager
http://damianblog.com/2006/11/27/scriptmanager-scriptpath/



 
 

ASP.NET Ajax :: Script Manager vs ToolkitScriptManager

http://blog.turlov.com/2008/05/scriptmanager-vs-toolkitscriptmanager.html

 

Configure Web.Config in order to use asp:ScriptManager

 

http://www.semenoff.dk/en/Code-Corner/ASP.Net.AJAX/WebService-From-JavaScript.aspx

How to call a Web Service from client-side JavaScript using ASP.Net AJAX

 



http://july-code.blogspot.com/2008/07/how-to-call-remote-web-services-from.html


Friday, February 25, 2011

AJAX : ASPX GridView - DataSet - ASMX WebMethod

Consuming a Web Service using ASP.NET Ajax



AJAX Web Services in C#

http://www.dreamincode.net/forums/topic/34279-introduction-to-web-services-in-c%23/

Creating a basic web service that retrieves data from a database,
then passes a populated DataSet back to the calling page to populate a GridView control with it.

http://articles.sitepoint.com/article/net-web-services-5-steps
http://www.daniweb.com/forums/thread151766.html
http://www.netomatix.com/DGSimple.aspx

Calling web service using javascript

http://sandblogaspnet.blogspot.com/2010/05/calling-web-service-using-javascript.html
http://sandblogaspnet.blogspot.com/2010/04/calling-web-service-using-javascript.html
http://sandblogaspnet.blogspot.com/2010/03/calling-web-service-using-javascript.html


Return Array from Web Service
using ScriptManager & Javascript

http://ciappara.wordpress.com/2009/07/31/return-array-from-web-service-using-scriptmanager-javascript/



SimpleWebService , [ScriptService]
http://msdn.microsoft.com/en-us/library/system.web.script.services.scriptserviceattribute.aspx


ASP.NET 2.0 AJAX Extensions 1.0 (Setup Wizard)

Brief Description


ASP.NET AJAX is a set of technologies to add AJAX (Asynchronous JavaScript And XML) support to ASP.NET. It consists of a client-side script framework, server controls, and more.

 http://www.microsoft.com/downloads/

ASPAJAXExtSetup.msi
type or namespace name Script does not exist in the namespace System.Web
using System.Web.Extensions




Different methods to call Web Services from AJAX

 http://www.codeproject.com/KB/ajax/Ajax_and_Web_Services.aspx

 

 Client-Side Web Service Calls with AJAX Extensions

http://msdn.microsoft.com/en-us/magazine/cc163499.aspx



Understanding ASP.NET AJAX Web Services

http://www.asp.net/ajax/tutorials/understanding-asp-net-ajax-web-services



ScriptManager Enables AJAX In Your Web Apps
http://msdn.microsoft.com/en-us/magazine/cc163354.aspx#S3


Exposing Web Services to Client Script
http://msdn.microsoft.com/en-us/library/bb398998.aspx 


ASP.NET AJAX ScriptManager webservice

http://www.codedigest.com/Articles/ASPNET/387_Asynchronous_Access_To_WebServices_using_ScriptManager_in_AspNet_Ajax.aspx


Thursday, February 24, 2011

android.jar and KSOAP2

The android.jar file is 11MB!

   Android does not contain any tools to help building SOAP based web service clients.
Google seems to like  REST services. The SDK is not bundled with any SOAP-related tools.
An alternative is to add kSOAP 2 to (Java ME) projects ... Or better we can use ksoap2 for android

   If an Android Activity access the internet via HTTP connection
the following line must be added to  AndroidManifest.xml :


http://romenlaw.blogspot.com/search/label/Web%20Service
http://romenlaw.blogspot.com/2008/08/consuming-web-services-from-android.html
http://www.android10.org/index.php/articleslibraries/167-using-ksoap2-for-android-soap-web-service


In general the Android API is very complete and offeres support for a whole lot of features and task. I did however have to find out that SOAP support is generally non existant. Given the widely known problems with SOAP and the trend towards simpler REST based services and the young age of the Android platform this is not too surprising. However in reality many people still need to work with legacy SOAP services.

http://www.simpligility.com/2010/05/attribute-support-for-ksoap2-on-android/

When you research on the web for SOAP support libraries on embedded devices including Android
you end up running into KSOAP and KSOAP2.
KSOAP2 library is used on J2ME devices like RIM Blackberry, and now Android.

On Android  KSOAP2 is alive :
http://code.google.com/p/ksoap2-android/updates/list

Unfortunately everything around KSOAP for JavaME seems to be rather old and inactive.
The project has a few issues assigned and had no activity for a while.

Return SalesAgents byName Or byZone

http://www.flickr.com/photos/24834074@N04/5472432292/sizes/l/in/photostream/
http://www.flickr.com/photos/24834074@N04/5471839947/sizes/l/in/photostream/
http://www.flickr.com/photos/24834074@N04/5472432212/sizes/l/in/photostream/
http://www.flickr.com/photos/24834074@N04/5471839801/sizes/l/in/photostream/



public class SalesAgent
{
    private string _name     = string.Empty;
    private string _surname  = string.Empty;
    private string _userID   = string.Empty;
    private string _zoneID   = string.Empty;
    private string _zoneName = string.Empty;
    private string _password = string.Empty;
   
    public SalesAgent(){}

    public string Name
    {
        get { return _name;  }
        set { _name = value; }
    }

    public string Surname
    {
        get { return _surname;  }
        set { _surname = value; }
    }

    public string UserID
    {
        get { return _userID;  }
        set { _userID = value; }
    }

    public string ZoneID
    {
        get { return _zoneID;  }
        set { _zoneID = value; }
    }

    public string ZoneName
    {
        get { return _zoneName; }
        set { _zoneName = value; }
    }
   
    public string Password
    {
        get { return _password;  }
        set { _password = value; }
    }

}


[WebMethod(Description = "Method to obtain SalesAgents by Zone or by Name")]
public SalesAgent[] ReturnSalesAgents(string theZone, string theAgent)
{

    SqlConnection dbConn = new SqlConnection(connStr);
    dbConn.Open();
    string sqlSelect = " ";
    if ( theZone.Equals("") && theAgent.Equals("") ) {
    sqlSelect = " SELECT TOP (100) dbo.PersoanaFizica.Nume as Name,
                          dbo.PersoanaFizica.Prenume as Surname,  " +
                       " dbo.Utilizator.UtilizatorID as UserID, dbo.Utilizator.Parola as Password,
                         dbo.Utilizator.ZonaID as ZoneID, " +
                       " dbo.Zona.Denumire as ZoneName " +
                       " FROM dbo.PersoanaFizica , dbo.Zona , dbo.Utilizator  " +
                       " WHERE dbo.PersoanaFizica.PersoanaFizica_ID = dbo.Utilizator.UtilizatorID and " +
                       " dbo.Utilizator.ZonaID = dbo.Zona.Id " +
                       " ORDER BY dbo.PersoanaFizica.Nume, dbo.PersoanaFizica.Prenume ";
    }
    else if (theAgent.Equals(""))
    {
        sqlSelect = " SELECT TOP (100) dbo.PersoanaFizica.Nume as Name,
                            dbo.PersoanaFizica.Prenume as Surname,  " +
                           " dbo.Utilizator.UtilizatorID as UserID, dbo.Utilizator.Parola as Password,
                             dbo.Utilizator.ZonaID as ZoneID, " +
                           " dbo.Zona.Denumire as ZoneName" +
                           " FROM dbo.PersoanaFizica , dbo.Zona , dbo.Utilizator  " +
                           " WHERE dbo.PersoanaFizica.PersoanaFizica_ID = dbo.Utilizator.UtilizatorID and " +
                           " dbo.Utilizator.ZonaID = dbo.Zona.Id and " +
                           " dbo.Zona.Denumire LIKE" + "'%" + theZone + "%'" +
                           " ORDER BY dbo.PersoanaFizica.Nume, dbo.PersoanaFizica.Prenume ";
    }
    else {
        sqlSelect = " SELECT TOP (100) dbo.PersoanaFizica.Nume as Name,
                              dbo.PersoanaFizica.Prenume as Surname,  " +
                           " dbo.Utilizator.UtilizatorID as UserID, dbo.Utilizator.Parola as Password,
                              dbo.Utilizator.ZonaID as ZoneID, " +
                           " dbo.Zona.Denumire as ZoneName" +
                           " FROM dbo.PersoanaFizica , dbo.Zona , dbo.Utilizator  " +
                           " WHERE dbo.PersoanaFizica.PersoanaFizica_ID = dbo.Utilizator.UtilizatorID and " +
                           " dbo.Utilizator.ZonaID = dbo.Zona.Id and " +
                           " ( dbo.PersoanaFizica.Nume LIKE " + "'%" + theAgent + "%' or
                               dbo.PersoanaFizica.Prenume LIKE " + "'%" + theAgent + "%' )";
    }
   
   
    SqlDataAdapter da = new SqlDataAdapter(sqlSelect, dbConn);
    DataTable dt = new DataTable();
    SqlCommand dbCommand = new SqlCommand(sqlSelect, dbConn);
    da.Fill(dt);
    dbConn.Close();
    List list = new List();
    foreach (DataRow row in dt.Rows)
    {
        SalesAgent target = new SalesAgent();
        target.Name = row["Name"].ToString();
        target.Surname = row["Surname"].ToString();
        target.ZoneID = row["ZoneID"].ToString();
        target.UserID = row["UserID"].ToString();
        target.Password = row["Password"].ToString();
        target.ZoneName = row["ZoneName"].ToString();
        list.Add(target);
    }
    return list.ToArray();
}

Wednesday, February 23, 2011

Web Service call with a String as a parameter

ASP.NET Web Service ( ASMX ) call from Android with a String parameter :

http://www.flickr.com/photos/24834074@N04/5469116121/sizes/l/in/photostream/

http://www.flickr.com/photos/24834074@N04/5469710588/sizes/l/in/photostream/
http://www.flickr.com/photos/24834074@N04/5469116261/sizes/l/in/photostream/
http://www.flickr.com/photos/24834074@N04/5469710484/sizes/l/in/photostream/


[WebMethod(Description = "Method to obtain Orders By Zone")]
public Order[] ReturnOrdersByZone(string theZone)
{

    SqlConnection dbConn = new SqlConnection(connStr);
    dbConn.Open();

    string sqlSelect = " SELECT TOP (100) dbo.PersoanaFizica.Nume as Name , dbo.PersoanaFizica.Prenume as Surname, dbo.Zona.Denumire AS Zone, dbo.Persoana.Denumire AS Client , dbo.[Document].Control " +
" FROM dbo.[Document] INNER JOIN " +
" dbo.PersoanaFizica ON dbo.[Document].Utilizator_ID =
dbo.PersoanaFizica.PersoanaFizica_ID INNER JOIN " +
 " dbo.Persoana ON dbo.[Document].Persoana_ID = dbo.Persoana.PersoanaID INNER JOIN " +
 " dbo.Comanda ON dbo.[Document].DocumentID = dbo.Comanda.Comanda_ID INNER JOIN  " +
 " dbo.Utilizator ON dbo.[Document].Utilizator_ID = dbo.Utilizator.UtilizatorID INNER JOIN " +
                   " dbo.Zona ON dbo.Utilizator.ZonaID = dbo.Zona.Id " +
                   " WHERE  (dbo.Zona.Denumire LIKE" + "'%" + theZone + "%')" +
                   " ORDER BY Control DESC ";


    SqlDataAdapter da = new SqlDataAdapter(sqlSelect, dbConn);
    DataTable dt = new DataTable();
    SqlCommand dbCommand = new SqlCommand(sqlSelect, dbConn);
    da.Fill(dt);
    dbConn.Close();
    List list = new List();
    foreach (DataRow row in dt.Rows)
    {
        // Person target = Activator.CreateInstance();
        Order target = new Order();
        target.Name = row["Name"].ToString();
        target.Surname = row["Surname"].ToString();
        target.Zone = row["Zone"].ToString();
        target.Client = row["Client"].ToString();
        target.Control = row["Control"].ToString();
        list.Add(target);
    }
    return list.ToArray();
}

Monday, February 21, 2011

LateOrders

http://code.google.com/p/jtelmon/source/browse/trunk/LateOrders/src/ro/jlsoft/lateorders


<%@ WebService class = "ReturnOrders" Language="C#" Debug = "true"%>


using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data;
using System.Data.SqlClient;
using System.Web.Services;

public class Order
{
    private string _name = string.Empty;
    private string _surname = string.Empty;
    private string _zone = string.Empty;
    private string _client = string.Empty;
    private string _control = string.Empty;
   
    public Order() {}

    public string Name
    {
        get { return _name; }
        set { _name = value; }
    }
 
    public string Zone
    {
        get { return _zone; }
        set { _zone = value; }
    }
   
    public string Surname
    {
        get { return _surname; }
        set { _surname = value; }
    }

    public string Client
    {
        get { return _client; }
        set { _client = value; }
    }

    public string Control
    {
        get { return _control; }
        set { _control = value; }
    }
   
}

public class ReturnOrders : WebService
{

   const string connStr = "server=192.168.61.28;uid=sa;pwd=wy;database=Pan";



[WebMethod(Description = "Method to obtain All User Info")]
public Order[] ReturnArray()
{

    SqlConnection dbConn = new SqlConnection(connStr);
    dbConn.Open();
   

    string sqlSelect = " SELECT TOP (100) dbo.PersoanaFizica.Nume as Name , dbo.PersoanaFizica.Prenume as Surname, dbo.Zona.Denumire AS Zone, dbo.Persoana.Denumire AS Client , dbo.[Document].Control " +
" FROM dbo.[Document] INNER JOIN " +
" dbo.PersoanaFizica ON dbo.[Document].Utilizator_ID = dbo.PersoanaFizica.PersoanaFizica_ID INNER JOIN " +
    " dbo.Persoana ON dbo.[Document].Persoana_ID = dbo.Persoana.PersoanaID INNER JOIN " +
    " dbo.Comanda ON dbo.[Document].DocumentID = dbo.Comanda.Comanda_ID INNER JOIN  " +
    " dbo.Utilizator ON dbo.[Document].Utilizator_ID = dbo.Utilizator.UtilizatorID INNER JOIN " +
    " dbo.Zona ON dbo.Utilizator.ZonaID = dbo.Zona.Id " +
    " WHERE  (dbo.Zona.Denumire LIKE '%RESITA%') " +
    " ORDER BY Control DESC ";   
   
   
    SqlDataAdapter da = new SqlDataAdapter(sqlSelect, dbConn);
    DataTable dt = new DataTable();
    SqlCommand dbCommand = new SqlCommand(sqlSelect, dbConn);
    da.Fill(dt);   
    dbConn.Close();
    List list = new List();
    foreach(DataRow row in dt.Rows) {
        // Person target = Activator.CreateInstance();
        Order target = new Order();
        target.Name = row["Name"].ToString();
        target.Surname = row["Surname"].ToString();
        target.Zone = row["Zone"].ToString();
        target.Client = row["Client"].ToString();
        target.Control = row["Control"].ToString();
        list.Add(target);
    }
    return list.ToArray();
}

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

}

Tuesday, February 15, 2011

PersonPassport4a.asmx

Returning an ArrayList of Person class instead of Person[] :


[WebMethod]
public ArrayList GetPersonArrayList()
{
    SqlConnection dbConn = new SqlConnection(connStr);
    dbConn.Open();
    string sqlSelect = "select * from users ";
    SqlDataAdapter da = new SqlDataAdapter(sqlSelect, dbConn);
    DataTable dt = new DataTable();
    SqlCommand dbCommand = new SqlCommand(sqlSelect, dbConn);
    da.Fill(dt);
    dbConn.Close();
    ArrayList myList = new ArrayList();
    foreach (DataRow row in dt.Rows)
    {
        Person target = new Person();
        target.Name = row["Name"].ToString();
        target.UserName = row["UserName"].ToString();
        target.EMail = row["EMail"].ToString();
        target.Password = row["Password"].ToString();
        myList.Add(target);
    }
    return myList;





[WebMethod(Description = "Method to obtain All User Info")]
public Person[] ReturnArray()
{
    SqlConnection dbConn = new SqlConnection(connStr);
    dbConn.Open();
    string sqlSelect = "select * from users ";
    SqlDataAdapter da = new SqlDataAdapter(sqlSelect, dbConn);
    DataTable dt = new DataTable();
    SqlCommand dbCommand = new SqlCommand(sqlSelect, dbConn);
    da.Fill(dt);   
    dbConn.Close();
    List list = new List();
    foreach(DataRow row in dt.Rows) {
        // Person target = Activator.CreateInstance();
        Person target = new Person();
        target.Name = row["Name"].ToString();
        target.UserName = row["UserName"].ToString();
        target.EMail = row["EMail"].ToString();
        target.Password = row["Password"].ToString();
        // DataColumnAttribute.Bind(row,target);
        list.Add(target);
    }
    return list.ToArray();
}

PersonPassport4.asmx - Simple webservice : INSERT UPDATE DELETE

Web Service C#.NET :
DB.SQL.TABLE as ARRAY
Android Client Consumer


From SOAP to WCF REST without LINQ : small and easy steps

PersonPassport2.asmx
http://code.google.com/p/jtelmon/source/browse/trunk/AndroidViews/PersonPassport2.asmx
http://jtelmon.googlecode.com/svn/trunk/AndroidViews/PersonPassport2.asmx

Building XML Web Services Using C# and ASP.NET



CREATE DATABASE minipassport 
GO 

CREATE TABLE Users ( 
UserName varchar (10) Primary Key NOT NULL , 
Name varchar (50) NOT NULL , 
EMail varchar (100) NOT NULL , 
Password varchar (10) NOT NULL 
) ON PRIMARY 
GO


http://www.flickr.com/photos/24834074@N04/5446222119/sizes/l/
http://www.flickr.com/photos/24834074@N04/5446222063/sizes/l/
http://www.flickr.com/photos/24834074@N04/5446839620/sizes/l/

http://code.google.com/p/jtelmon/source/browse/trunk/LocalPassport/src/passport/bimbim/in/MainLP2.java
http://code.google.com/p/jtelmon/source/browse/trunk/LocalPassport/src/passport/bimbim/in
http://code.google.com/p/jtelmon/source/browse/trunk/LocalPassport

<%@ WebService class = "PersonPassport2" Language="C#" Debug = "true"%>

using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data;
using System.Data.SqlClient;
using System.Web.Services;


public class Person

{

    private string _name = string.Empty;
    private string _user_name = string.Empty;
    private string _eMaiL = string.Empty;
    private string _password = string.Empty;

  public Person() {}




    public string Name

    {

        get { return _name; }

        set { _name = value; }

    }

   
        public string Password

    {

        get { return _password; }

        set { _password = value; }

    }

   
   
    public string UserName

    {

        get { return _user_name; }

        set { _user_name = value; }

    }

    public string EMail

    {

        get { return _eMaiL; }

        set { _eMaiL = value; }

    }

        

}

public class PersonPassport2 : WebService
{
const string connStr = "server=localhost;uid=sa;pwd=kash;database=minipassport";

[WebMethod(Description = "Method to Authenticate Users")]
public bool Authenticate(string username, string password)
{
SqlConnection dbConn = new SqlConnection(connStr);
string sqlStr = "Select password from users where username = '" + username + "';";
dbConn.Open();
SqlCommand dbCommand = new SqlCommand(sqlStr,dbConn);
SqlDataReader dbReader = dbCommand.ExecuteReader();

bool returnBool;
if (dbReader.Read())
{
if (dbReader[0].ToString()==password)
{
returnBool = true;
}
else
{
returnBool = false;
}
}
else
{
returnBool=false;
}
dbReader.Close();
dbConn.Close();
return returnBool;
}

[WebMethod(Description = "Method to Add User")]
public bool AddUser(string username, string password, string name, string email)
{
bool returnBool = false;
SqlConnection dbConn = new SqlConnection(connStr);
string sqlStr = "INSERT INTO users(username,password,name,email) values('" + username + "', '" + password + "', '" + name + "', '" + email + "');";
SqlCommand dbCommand = new SqlCommand(sqlStr,dbConn);
try
{
dbConn.Open();
if (dbCommand.ExecuteNonQuery()!=0)
{
returnBool=true;
}
returnBool=true;
}
catch
{
returnBool=false;
}
dbConn.Close();
return returnBool;
}

[WebMethod(Description = "Method to Delete User")]
public bool DeleteUser(string username)
{
bool returnBool = false;
SqlConnection dbConn = new SqlConnection(connStr);
string sqlStr = "DELETE FROM users where username = '" + username +"';";
SqlCommand dbCommand = new SqlCommand(sqlStr,dbConn);
try
{
dbConn.Open();
if (dbCommand.ExecuteNonQuery()!=0)
{
returnBool=true;
}
}
catch
{
returnBool=false;
}
dbConn.Close();
return returnBool;
}

[WebMethod(Description = "Method to Edit User Information")]
public bool EditUser(string username, string name, string email)
{
bool returnBool = false;
SqlConnection dbConn = new SqlConnection(connStr);
string sqlStr = "UPDATE users SET username = '" + username +"',name = '"+name+"',email= '"+email+"';";
SqlCommand dbCommand = new SqlCommand(sqlStr,dbConn);
try
{
dbConn.Open();
if (dbCommand.ExecuteNonQuery()!=0)
{
returnBool=true;
}
}
catch
{
returnBool=false;
}
dbConn.Close();
return returnBool;
}

[WebMethod(Description = "Method to Change User Password")]
public bool ChangePassword(string username, string password)
{
bool returnBool = false;
SqlConnection dbConn = new SqlConnection(connStr);
string sqlStr = "UPDATE users SET password = '"+password+"';";
SqlCommand dbCommand = new SqlCommand(sqlStr,dbConn);
try
{
dbConn.Open();
if (dbCommand.ExecuteNonQuery()!=0)
{
returnBool=true;
}
}
catch
{
returnBool=false;
}
dbConn.Close();
return returnBool;
}

[WebMethod(Description = "Method to Obtain User Name")]
public string ReturnName(string username)
{
SqlConnection dbConn = new SqlConnection(connStr);
string sqlStr = "Select Name from users where username = '" + username + "';";
dbConn.Open();
SqlCommand dbCommand = new SqlCommand(sqlStr,dbConn);
SqlDataReader dbReader = dbCommand.ExecuteReader();
dbReader.Read();
string _name = dbReader[0].ToString();
dbReader.Close();
dbConn.Close();
return _name;
}

[WebMethod(Description = "Method to obtain User Email Address")]
public string ReturnEmail(string username)
{
SqlConnection dbConn = new SqlConnection(connStr);
string sqlStr = "Select email from users where username = '" + username + "';";
dbConn.Open();
SqlCommand dbCommand = new SqlCommand(sqlStr,dbConn);
SqlDataReader dbReader = dbCommand.ExecuteReader();
dbReader.Read();
string _name = dbReader[0].ToString();
dbReader.Close();
dbConn.Close();
return _name;
}

[WebMethod(Description = "Method to obtain All User Info")]
public DataSet ReturnAll()
{
    SqlConnection dbConn = new SqlConnection(connStr);
    dbConn.Open();
    string sqlSelect = "select * from users ";
    SqlDataAdapter da = new SqlDataAdapter(sqlSelect, dbConn);
    DataSet ds = new DataSet();
    SqlCommand dbCommand = new SqlCommand(sqlSelect, dbConn);
    da.Fill(ds, "users");
    dbConn.Close();
    return ds;
}

[WebMethod(Description = "Method to obtain All User Info")]
public Person[] ReturnArray()
{
    SqlConnection dbConn = new SqlConnection(connStr);
    dbConn.Open();
    string sqlSelect = "select * from users ";
    SqlDataAdapter da = new SqlDataAdapter(sqlSelect, dbConn);
    DataTable dt = new DataTable();
    SqlCommand dbCommand = new SqlCommand(sqlSelect, dbConn);
    da.Fill(dt);   
    dbConn.Close();
    List list = new List();
    foreach(DataRow row in dt.Rows) {
        // Person target = Activator.CreateInstance();
        Person target = new Person();
        target.Name = row["Name"].ToString();
        target.UserName = row["UserName"].ToString();
        target.EMail = row["EMail"].ToString();
        target.Password = row["Password"].ToString();
        // DataColumnAttribute.Bind(row,target);
        list.Add(target);
    }
    return list.ToArray();
}


 [WebMethod]
    public Person GetSingle()
    {
        Person person = new Person();
        person.Name = "bimbim.in";
        //person.Age = 30;
        //person.Dob = new System.DateTime(1980, 01, 15);
        //person.Salary = 50000f;
        return person;
    }

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

}











Dumped Database can be downloaded at :
https://docs.google.com/leaf?id=0BzKVfKe--t_cYjAzOTk5YmEtNjk1ZS00ZTcxLWIzMDgtYTMwMTVlMTQwZDVi&hl=en_GB





Monday, February 14, 2011

Cars , Coffe Makers , Wash Machines , Google TV , Intel Atom , SoC , Sony , Logitech

http://www.informationweek.com/news/hardware/processors/showArticle.jhtml?articleID=229100344


Intel is most enthusiastic about Smart TV. That's the Internet-enabled television platform co-developed with Google, Sony, and Logitech.


For years, there have been processors inside televisions and appliances. The difference today is that embedded computing on the consumer front is poised for a major expansion.
That's because consumer embedded apps like TVs, washing machines, and coffee makers are doing what desktop PCs did back in the 1990s -- they're transitioning from standalone bricks into Web-connected appliances. This is pretty simple technically but also profound in terms of market impact. We're talking about millions of televisions, cars, etc ...

Friday, February 11, 2011

Creating a REST Client using WCF - Twitter's REST API

http://www.switchonthecode.com/tutorials/creating-a-rest-client-using-wcf

A couple of weeks ago we received an email about consuming a REST service in WCF. Well, this tutorial should answer that email. Today we're going to build a simple client for Twitter's REST API using WCF.


netbeans.org : Getting Started with RESTful Web Services

http://netbeans.org/kb/docs/websvc/rest.html

CRUD in RESTful Services of WCF-Tutorial

http://www.codegain.com/articles/wcf/restservice/crud-in-restful-services-of-wcf-tutorial.aspx

using System.Collections.Generic;


[WebGet(UriTemplate = "contacts")]
    [OperationContract]
    List GetAllContacts();

It is possible to return from an soap ASMX a generic collection
List of Contacts instead of a DataSet of Contacts ?



Note : The notion of building UriTemplate is to specify some form of unique Uri.
Always keep in mind, the external world will request the service using the URI.
Now lets go to our ServiceHost application and configure the service to use REST based approach.
Basically for REST based service you need to use webHttpBinding as Binding configuration.

Step by Step tutorial of REST Enabled Service in WCF

, wOutput 100 is returned in the browser by the service.
It is because, below service method. URI of below GET method is mapped to root of the URI.


http://www.dotnetspark.com/kb/1373-step-by-step-tutorial-rest-enabled-service.aspx

<%@ ServiceHost Language="C#" Debug="true"
Service="RestServicePublishing.RestService"
CodeBehind="RestService.svc.cs"
Factory="System.ServiceModel.Activation.WebServiceHostFactory"%>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;


namespace RestServicePublishing
{

    [Serializable]
    public class NumberService
    {
        public int Number1 { get; set; }
        public int Number2 { get; set; }
    }

    [ServiceContract]
    public interface IRestService
    {
        [OperationContract(Name="AddParameter")]
        [WebInvoke(UriTemplate = "/",Method="POST")]
        int  Add(NumberService n1);
        [OperationContract(Name="Add")]
        [WebGet(UriTemplate = "/")]
        int Add();

    
    }


    public class RestService : IRestService
    {
        public int res = 100;

        public int Add(NumberService n1)
        {

            res = Convert.ToInt32(n1.Number1) + Convert.ToInt32(n1.Number2);
            return res;
        }
        public int Add()
        {
            return res;
        }

    }
}





Exposing RESTful Services Using WCF

http://www.drdobbs.com/windows/227600076

Implementing the TestService WCF Service

The WCF Service class called TestService implements the WCF Service Contract implemented earlier -- it defines the two methods declared in the WCF Service Contract. Here's what the class looks like:


<%@ ServiceHost Language="C#" Debug="true" Service="RESTService.TestService" CodeBehind="TestService.svc.cs" %>

using System;

using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;

namespace RESTService
{

[ServiceContract]
public interface ITestService
{
[OperationContract]
[WebGet]
Employee GetEmployee(Int32 employeeID);
[WebInvoke]
Employee PostEmployee(Int32 employeeID);
}

[DataContract(Namespace = "")]
public class Employee
{
[DataMember]
public Int32 EmployeeID { get; set; }
[DataMember]
public string FirstName { get; set; }
[DataMember]
public string LastName { get; set; }
[DataMember]
public String Address { get; set; }
}

public class TestService : ITestService
{
public Employee GetEmployee(Int32 employeeID)
{
return new Employee { EmployeeID = employeeID, FirstName = "Joydip", LastName = "Kanjilal" };
}

public Employee PostEmployee(Int32 employeeID)
{
return new Employee { EmployeeID = employeeID, FirstName = "Joydip", LastName = "Kanjilal" };
}
}
}

WCF Web Services The Easy Way

In fact, we are going to setup WCF web services without any configuration!
To make it even more simple, you could move the code for the service out of the CodeBehind file and into the .svc file. Now you have an entire WCF service in a single file! Check it out:

http://www.codethinked.com/post/2010/08/17/WCF-Web-Services-The-Easy-Way.aspx
http://twitter.com/JustinEtheredge

<%@ ServiceHost Language="C#"
Service="MyTestWebsite.MyTestService"
Factory="System.ServiceModel.Activation.ServiceHostFactory" %>
using System.ServiceModel;

namespace MyTestWebsite
{
[ServiceContract]
public class MyTestService
{
[OperationContract]
public string DoWork()
{
return "Did Something!";
}
}
}

Android Activity and sub-Activity

http://developerlife.com/tutorials/?p=302

Android 101

To get started with Android, click here.

What’s an activity?

An activity is the equivalent of a Frame/Window in GUI toolkits. It takes up the entire drawable area of the screen (minus the status and title bars on top). An activity is what gets bound to the AndroidManifest.xml as the main entry point into an application. For long running tasks, it’s best to use a service that talks to this activity.

Service

Activities are meant to display the UI and get input from the user. However, long running tasks are not meant to be spawned in a activity, since they can be frozen when the focus is switched away from them (by the user or incoming phone call or system event). Services on the other hand keep running for the duration of the user’s ‘session’ on the device.

WCF - Windows Comunication Framwwork

Creating your First WCF Service

http://www.youtube.com/watch?v=JlyND7b2-YA

Developing a REST Web Service
using C# - A walkthrough

http://www.codeproject.com/KB/webservices/RestWebService.aspx

Part # 1
- Create a simple database which contains an Employee table


Part # 2
– Create an Employee class as a placeholder
for the database employee information


Part # 3
- Code basic database operations like
Read, Update, Delete, Insert for Employee


Part # 4
- Create the REST Web Service


Part # 5
- Deploying the application


Part # 6
- Testing the application


References


Issues in deploying applications in IIS -
http://www.codeproject.com/KB/ISAPI/Curious-Case-IIS.aspx

HTTP handlers - http://msdn.microsoft.com/en-us/library/bb398986.aspx
REST - http://www.codeproject.com/KB/architecture/RESTWebServicesPart1.aspx
REST - http://tomayko.com/writings/rest-to-my-wife

Friday, February 4, 2011

PersonPassport2 C# WebService

http://bimbim.in/post/2010/10/08/Android-Calling-Web-Service-with-complex-types.aspx

http://code.google.com/p/jtelmon/source/browse/trunk/Bimbimin.Original.Android.Webservice.Client/

http://code.google.com/p/jtelmon/source/browse/Tips4Java/src/BimBimWS

http://www.flickr.com/photos/24834074@N04/5416340301/

http://www.flickr.com/photos/24834074@N04/5416340257/



<%@ WebService class = "PersonPassport2" Language="C#" Debug = "true"%>

using System;
using System.Data;
using System.Data.SqlClient;
using System.Web.Services;

public class Person

{

private string _name = string.Empty;

private int _age = 0;

private float _salary = 100000.0f;

private System.DateTime _dob = new DateTime(1980, 01, 15);


public Person() {}

public Person(string firstname, string lastname, DateTime dob)
{
this._name = firstname+lastname;
this._dob = dob;
}


public float Salary

{

get { return _salary; }

set { _salary = value; }

}

public System.DateTime Dob

{

get { return _dob; }

set { _dob = value; }

}



public int Age

{

get { return _age; }

set { _age = value; }

}

public string Name

{

get { return _name; }

set { _name = value; }

}



}

public class PersonPassport2 : WebService
{
const string connStr = "server=localhost;uid=sa;pwd=kashcaval;database=minipassport";

[WebMethod(Description = "Method to Authenticate Users")]
public bool Authenticate(string username, string password)
{
SqlConnection dbConn = new SqlConnection(connStr);
string sqlStr = "Select password from users where username = '" + username + "';";
dbConn.Open();
SqlCommand dbCommand = new SqlCommand(sqlStr,dbConn);
SqlDataReader dbReader = dbCommand.ExecuteReader();

bool returnBool;
if (dbReader.Read())
{
if (dbReader[0].ToString()==password)
{
returnBool = true;
}
else
{
returnBool = false;
}
}
else
{
returnBool=false;
}
dbReader.Close();
dbConn.Close();
return returnBool;
}

[WebMethod(Description = "Method to Add User")]
public bool AddUser(string username, string password, string name, string email)
{
bool returnBool = false;
SqlConnection dbConn = new SqlConnection(connStr);
string sqlStr = "INSERT INTO users(username,password,name,email) values('" + username + "', '" + password + "', '" + name + "', '" + email + "');";
SqlCommand dbCommand = new SqlCommand(sqlStr,dbConn);
try
{
dbConn.Open();
if (dbCommand.ExecuteNonQuery()!=0)
{
returnBool=true;
}
returnBool=true;
}
catch
{
returnBool=false;
}
dbConn.Close();
return returnBool;
}

[WebMethod(Description = "Method to Delete User")]
public bool DeleteUser(string username)
{
bool returnBool = false;
SqlConnection dbConn = new SqlConnection(connStr);
string sqlStr = "DELETE FROM users where username = '" + username +"';";
SqlCommand dbCommand = new SqlCommand(sqlStr,dbConn);
try
{
dbConn.Open();
if (dbCommand.ExecuteNonQuery()!=0)
{
returnBool=true;
}
}
catch
{
returnBool=false;
}
dbConn.Close();
return returnBool;
}

[WebMethod(Description = "Method to Edit User Information")]
public bool EditUser(string username, string name, string email)
{
bool returnBool = false;
SqlConnection dbConn = new SqlConnection(connStr);
string sqlStr = "UPDATE users SET username = '" + username +"',name = '"+name+"',email= '"+email+"';";
SqlCommand dbCommand = new SqlCommand(sqlStr,dbConn);
try
{
dbConn.Open();
if (dbCommand.ExecuteNonQuery()!=0)
{
returnBool=true;
}
}
catch
{
returnBool=false;
}
dbConn.Close();
return returnBool;
}

[WebMethod(Description = "Method to Change User Password")]
public bool ChangePassword(string username, string password)
{
bool returnBool = false;
SqlConnection dbConn = new SqlConnection(connStr);
string sqlStr = "UPDATE users SET password = '"+password+"';";
SqlCommand dbCommand = new SqlCommand(sqlStr,dbConn);
try
{
dbConn.Open();
if (dbCommand.ExecuteNonQuery()!=0)
{
returnBool=true;
}
}
catch
{
returnBool=false;
}
dbConn.Close();
return returnBool;
}

[WebMethod(Description = "Method to Obtain User Name")]
public string ReturnName(string username)
{
SqlConnection dbConn = new SqlConnection(connStr);
string sqlStr = "Select Name from users where username = '" + username + "';";
dbConn.Open();
SqlCommand dbCommand = new SqlCommand(sqlStr,dbConn);
SqlDataReader dbReader = dbCommand.ExecuteReader();
dbReader.Read();
string _name = dbReader[0].ToString();
dbReader.Close();
dbConn.Close();
return _name;
}

[WebMethod(Description = "Method to obtain User Email Address")]
public string ReturnEmail(string username)
{
SqlConnection dbConn = new SqlConnection(connStr);
string sqlStr = "Select email from users where username = '" + username + "';";
dbConn.Open();
SqlCommand dbCommand = new SqlCommand(sqlStr,dbConn);
SqlDataReader dbReader = dbCommand.ExecuteReader();
dbReader.Read();
string _name = dbReader[0].ToString();
dbReader.Close();
dbConn.Close();
return _name;
}

[WebMethod(Description = "Method to obtain All User Info")]
public DataSet ReturnAll()
{
SqlConnection dbConn = new SqlConnection(connStr);
dbConn.Open();
string sqlSelect = "select * from users ";
SqlDataAdapter da = new SqlDataAdapter(sqlSelect, dbConn);
DataSet ds = new DataSet();
SqlCommand dbCommand = new SqlCommand(sqlSelect, dbConn);
da.Fill(ds, "users");
dbConn.Close();
return ds;
}

[WebMethod]
public Person GetSingle()
{
Person person = new Person();
person.Name = "bimbim.in";
person.Age = 30;
person.Dob = new System.DateTime(1980, 01, 15);
person.Salary = 50000f;
return person;
}

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

}

C# HelloWorld WebService

<%@ WebService Language="C#" class="HelloWorld"%>

using System.Web.Services;

public class HelloWorld : WebService
{
[WebMethod]
public string HelloWorldMethod()
{
return "Hello World";
}
}