In order to convert a C# generic list to json string and vice versa,
Add reference to System.Web.Extensions in your project.
//Assume that, you have a generic list as shown below,
List<Patient> patientList = GetPatients();
//use Serialize method to convert patient list to json string
string JStr = serializer.Serialize(patientList);
//Now, the json string can be set to generic list of type patient as shown below,
List<Patient> nList = new List<Patient>();
nList = serializer.Deserialize<List<Patient> >(JStr);
DOWNLOAD the working sample here https://docs.google.com/file/d/0By3at1G2EGgOal9IMW5pQjNTNXM/edit (File->Download)
In order to consume WCF service in an Android application, the WCF Service must send and receive data in JSON format. So, you need to set the RequestFormat and ResponseFormat to JSON, in the WebInvoke attribute as shown below,
public interface IService
[WebInvoke(Method = “POST”,
UriTemplate = “/GetEmployee”,
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json)]
Employee GetEmployee(EmployeeIdentity request);
I used wsHttpBinding in my WCF service.
Now, to consume the WCF Service in your Android application, use httpClient to process the request and get the response. A sample code is given below,
HttpClient httpClient = null;
HttpUriRequest httpUriRequest = null
HttpResponse httpResponse = null;
httpUriRequest = //build request
httpClient = new DefaultHttpClient();
httpResponse = httpClient.execute(httpUriRequest);
I got this error message when I created my first android application. Right after creating the application, when I tried to run, the error message was displayed. I fixed this error message by selecting the android sdk version in the java build path. That is, select the project and goto its properties. Select Java Build Path, check the android sdk version in the ‘order and export’ tab. See the image below,
this will fix the error message. Now you will be able to run your android application.
In this post, I am going to explain the steps involved in setting up Android development environment.
–goto developer.android.com & SDK (Android SDK 2.2)
–download Eclipse IDE for Java Developers for Windows (Eclipse IDE for Java Developers Windows 32 bit)
–download JDK 6
-Install JDK first
-Extract Android to D:\AndroidSDK. Follow the instructions given in the SDK Readme.txt file.
-Extract Eclipse package
Configure Android Development Tools Plug-in
—goto Help->Install New Software
—Click on Add button
—Type Google Android as the name in the popup
—TYpe https://dl-ssl.google.com/android/eclipse in the Location and click OK
–Check the checkbox & click next
–Accept the Terms & Conditions and click on Finish
–Goto Window -> Preferences.
–Select Android from left pane
–Select the Android SDK location and Apply
You must create an Android Virtual Device (AVD).
An AVD defines the system image and device settings used by the emulator.
-Create an AVD:
—In Eclipse, choose Window > Android SDK and AVD Manager.
—Select Virtual Devices in the left panel.
—Click New. The Create New AVD dialog appears.
—Keyin the name of the AVD, such as “demoavd”.
—Choose a target platform (say, android 2.2) you want to run on the emulator.
—Click Create AVD.
Create a new project
-Choose an Android project
-Specify Project Name
Thats all! Enjoy creating Android applications!