using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;

namespace xamarin
{
    [Activity(Label = "WCF Service in Xamarin Android App", MainLauncher = true, Icon = "@drawable/icon")]
    public class MainActivity : Activity
    {
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.Main);

            Button button = FindViewById<Button>(Resource.Id.btnAdd);

            button.Click += delegate
            {
                var apiResult = FindViewById<TextView>(Resource.Id.labelAPIResult);
                apiResult.Text = "";
                var request = System.Net.WebRequest.Create("http://172.16.3.17:8733/Service1/data/10");
                request.ContentType = "application/json";
                request.Method = "GET";
                using (System.Net.HttpWebResponse response = request.GetResponse() as System.Net.HttpWebResponse)
                {
                    using (System.IO.StreamReader reader = new System.IO.StreamReader(response.GetResponseStream()))
                    {
                        var content = reader.ReadToEnd();
                        var result = System.Text.RegularExpressions.Regex.Replace(content, @"[^a-zA-Z0-9]", "");
                        var addSpace = result.Replace("Name", " Name ");
                        var addedSpace = addSpace.Replace("Id", " Id ");
                        apiResult.Text = addedSpace;
                    }
                }
            };
        }
    }
}

