0
我已經完成了Google搜索,但沒有得到我在xamarin中使用WCF的要求。我有一個託管在本地IIS的Web應用程序,該應用程序也具有wcf服務。 我做了什麼。 1.創建名稱爲Myservice的wcf服務。以xamarin格式在Web應用程序中託管wcf
2.in myservice.cs中,有兩個方法,一個是validateUser和saveData。
3.我已經創建了另一個單獨的項目,因爲xamarin跨平臺共享或pcl。並已在那裏添加web服務引用。
我的代碼如下。
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;
}
}
在xamarin項目中創建如下服務類。
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
//}
}
現在我想在用戶點擊我驗證用戶像下面
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");
}
}
,但我無法在這裏找到驗證方法。
不使用本地主機。使用IP或FQDN – Jason
這將有助於獲取服務方法並將設置? – SajidBp