Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have done googled ,but not got my requirements in consuming WCF in xamarin.
I have a web application that is hosted at local IIS,that application also have wcf service.
what I have done.
1.created wcf service with name Myservice.

2.in myservice.cs ,there are two methods, one validateUser,and saveData.

3.I have create another separate project as xamarin cross plateform shared.or pcl .and has added webservice refernces there. my code is as follow.

Myservice.cs

C#
public bool SaveChallenData()
{
throw new NotImplementedException();
}
public bool ValidateUser(string UserId, string Password)
{
FYP_CMSEntities1 ef = new FYP_CMSEntities1();
if (!string.IsNullOrEmpty(UserId) && !string.IsNullOrEmpty(Password))
{
var login = (from ul in ef.UserLogins where ul.UserName == UserId select ul).FirstOrDefault();
if (login != null && login.Password == Password)
{
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
created a service class in xamarin project as below.
 
class Service
{
public static string SoapUrl = "http://localhost/FYP_Admin/webservices/cmsservice.svc";
ICMSService soapService;
public Service(ICMSService service)
{
soapService = service;
}
public Service()
{
soapService = new CMSServiceClient(
new BasicHttpBinding(),
new EndpointAddress(SoapUrl));
}
//public Task ValidateUser(string username,string password)
//{
// return soapService.BeginDoWork
//}
}


now i want on user click i validate user like below

C#
private void Button_Clicked(object sender, EventArgs e)
{
Service svc = new Service()
var endpoint = new EndpointAddress("http://localhost/FYP_Admin/webservices/cmsservice.svc");
var binding = new BasicHttpBinding
{
Name = "basicHttpBinding",
MaxBufferSize = 2147483647,
MaxReceivedMessageSize = 2147483647
};
string username = usernameEntry.Text.Trim();
string password = passwordEntry.Text.Trim();
bool result = svc.ValidateUser(username, password);
if (result == true)
{
App.Navigation.PushAsync(new MainPage());
}
else
{
DisplayAlert("Oops","Credentials are incorrect","Cancel");
}
}



But i could not find validate method here.


What I have tried:

i have mention what i have done
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900