Tuesday, November 8, 2011

Step 10 : Android client saves data to WCF REST


http://code.google.com/p/jtelmon/source/browse/trunk/AndroidViews/src/net/learn2develop/AndroidViews/SavePerson02.java
http://code.google.com/p/jtelmon/source/browse/trunk/AndroidViews/res/layout/save.xml
http://code.google.com/p/jtelmon/source/browse/trunk/AndroidViews/RestService


CREATE TABLE [dbo].[Users](
[UserName] [varchar](100) NOT NULL,
[Name] [varchar](100) NOT NULL,
[EMail] [varchar](100) NOT NULL,
[Password] [varchar](100) NOT NULL
}






Friday, November 4, 2011

ToDo : Android WCF adapter class

How to manipulate a  RESTful WCF Web Service in Android


after 9 steps of simple WCF samples 
Step 9 : Android Client reading JSON WCF REST
Step 8 : WCF RESTful GET JSON List with FIDDLER
it's time to incorporate them all in a single class called WCFadapter ... 

On the model of DBAdapter in the article Creating and Using Databases in Android
it's interesting to crate a similar class named WCFadapter ... 


It's also useful these samples : 

Building an Android Application in 6 Steps

Wednesday, November 2, 2011

Die Internet Explorer , Die !

Is Internet Explorer Dying? | ZDNet


In October 2011, according to NetMarketShare, IE is barely above the 50% mark of desktop browsers with 52.63%.
That only tells part of the story though.
On the smartphone/tablet market, IE is a total non-player with IE and Microsoft Pocket IE combined having only 0.17% of the market.
Put the total Web browser markets together, and you’ll see IE has finally dropped below the 50% mark.
IE now has only 49.58% of the total market.

Android Log.i LogCat


http://developer.android.com/reference/android/util/Log.html

Log.i can be used to log to LogCat Window in Eclipse :
Log.d can be used in debugging ;
Windows -> Show View -> Other -> Android -> LogCat




Debugging in Android using Eclipse


Android Essentials: Application Logging


WTF - What a Terrible Failure : 
Log.e() method is used to log errors.
Log.w() method is used to log warnings.
Log.i() method is used to log informational messages.
Log.d() method is used to log debug messages.
Log.v() method is used to log verbose messages.
Log.wtf() method is used to log terrible failures that should never happen. 

Step 9 : Android Client reading JSON WCF RESTful Web Service


Step 9 : Android Client reading JSON data from a WCF RESTful Web Service

Google Code of raw JSON data displayed on a Toast from the WebService: 
CLICK on PICTURES to ZOOM




Parsing JSON with JSONObject and JSONArray :
http://code.google.com/p/jtelmon/source/browse/trunk/AndroidViews/src/net/learn2develop/AndroidViews/GetPersons02.java




And finally JSON data from the WCF RESTful WebService 
http://code.google.com/p/jtelmon/source/browse/trunk/AndroidViews/RestService
displayed in a SimpleList
http://code.google.com/p/jtelmon/source/browse/trunk/AndroidViews/src/net/learn2develop/AndroidViews/GetPersons03.java

ListView GraphicalLayout :
http://code.google.com/p/jtelmon/source/browse/trunk/AndroidViews/res/layout/listview.xml


http://senior.ceng.metu.edu.tr/2009/praeda/2009/01/11/a-simple-restful-client-at-android/

Android JSON Parser Example

JSON in Android - Tutorial

Tuesday, November 1, 2011

How to format blog source code


http://libg.org/2008/09/11/how-to-format-source-code-in-your-blog/

http://google-code-prettify.googlecode.com/svn/trunk/README.html
http://code.google.com/p/syntaxhighlighter/wiki/Usage

There is WordPress plug-in Google Syntax Highlighter for WordPress, and convenient for WordPress users to integrate to your WordPress blog site. The plug-in author may be wrong here, because the true Google Code highlight tool is Google Code Prettify.


http://www.codeshode.com/2010/06/format-my-source-code-for-blogging.html
http://www.codeshode.com/2011/07/format-source-code-for-blogging-tool.html

Step 8 : WCF RESTful GET JSON List with FIDDLER


http://pantestmb.blogspot.com/2011/10/step-3-from-soap-to-wcf-restful-get.html

In Step 3 there was a sample of transforming a SOAP Web Service into a WCF RESTful one
with "application/xml" Content-Type ;

In step 7 - there are all the details about the full source code

To be accessed from a Android Client the sample must switch from XML to JSON data-content ;

Let's consider that the webservice is installed on the IP : 192.168.61.3 :
http://192.168.61.3/RestServicePost/RestServiceImpl.svc/json/getallpersons

The code behind the above link : 

        [OperationContract]
        [WebInvoke(Method = "GET",
            ResponseFormat = WebMessageFormat.Json,
            BodyStyle = WebMessageBodyStyle.Wrapped,
            UriTemplate = "json/getallpersons")]
        PersonData[] getJsonPersons();

        public PersonData[] getJsonPersons()
        {
            return getAllPersons();
        }


        public PersonData[] getAllPersons()
        {
            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();
                PersonData target = new PersonData();
                target.Name = row["Name"].ToString();
                target.User = row["UserName"].ToString();
                target.Email = row["EMail"].ToString();
                target.Password = row["Password"].ToString();
                // DataColumnAttribute.Bind(row,target);
                list.Add(target);
            }
            return list.ToArray();
        }

Pictures about what the code does ;
FIDDLER gets from the webservice all the persons from the database in JSON format :