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<TextView>(Resource.Id.myLabel);
- txtUserName = FindViewById<EditText>(Resource.Id.txtUserName);
- myButton = FindViewById<Button>(Resource.Id.myButton);
- myButton.Click += myButton_Click;
- }
-
- void myButton_Click(object sender, EventArgs e)
- {
- var textview = FindViewById<TextView>(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);
- }
- }
Getting error : Connection failure (Access denied)Give me some solution.
Thanks