I have created an WCF Service and hosted it on Server.
This application having simple functionality like Get record from a SQL Server database.
Now I am executing this WCF Service on button click event in Xamarin Android of MainActivity.cs
But this is not working. Give me some solution. If I run the same service code in Normal C# application then it is working fine.
Bellow is my code.
- public class MainActivity : Activity
- {
- TextView myLabel;
- EditText txtUserName;
- Button myButton;
- HttpClient Client;
- private string URIString;
- protected override void OnCreate(Bundle bundle)
- {
- Microsoft.WindowsAzure.MobileServices.CurrentPlatform.Init();
- base.OnCreate(bundle);
- SetContentView(Resource.Layout.Main);
- myLabel = FindViewById
(Resource.Id.myLabel); - txtUserName = FindViewById
(Resource.Id.txtUserName); - myButton = FindViewById
- myButton.Click += myButton_Click;
- }
- void myButton_Click(object sender, EventArgs e)
- {
- var textview = FindViewById
(Resource.Id.textView3); - var s = GetData();
- var finalResult = s;
- textview.Text = finalResult.ToString();
- }
- public string GetData()
- {
- try
- {
- var request = HttpWebRequest.Create("http://xxxxx:2498/MyRestService.svc/GetEmployee/1");
- request.ContentType = "application/json";
- request.Method = "GET";
- using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
- {
- using (StreamReader reader = new StreamReader(response.GetResponseStream()))
- {
- var content = reader.ReadToEnd();
- var cleanValue = System.Text.RegularExpressions.Regex.Replace(content, @"[^a-zA-Z0-9]", "");
- return cleanValue.ToString();
- }
- }
- }
- catch (Exception ex)
- {
- return ex.Message.ToString();
- }
- var t = "error occured !!!";
- return Convert.ToString(t);
- }
- }
Give me some solution.
Thanks

Rupesh KahanePosted Nov 15, 2016, 1:21 AM
I am new in Xamarin Development.
Very Important => if you are using any Web Service for your App then do not forget to give permissions to access Internet.
Steps:
1. Right-click on your android project and select Properties.
2. Select Android Manifest in the window that opens.
3. Check the permission that you want to require in the list of permissions i.e check the checkbox of "Internet"