Tech
Forums
Jobs
Books
Events
Interviews
Live
More
Learn
Training
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
1
Reply
WCF Service Connection Failure In Xamarin Android
Rupesh Kahane
Nov 10 2016 5:18 AM
441
Reply
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
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
1
)
Next Recommended Forum
how to import material design google icons into android
How to create session in Xamarin Android after login