TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Sajid Hussain
1.2k
514
100.7k
Consume WCF in xamarin shared project
Jul 14 2017 8:18 PM
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
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
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.
Reply
Answers (
0
)
How to create a Blog Post view
How to access web service in windows application