Hi,
Please help. When i tried to connect WCF service from my Xamarain Client. Not Connect. As the same time i wrote one small VB Desktop form and connect to WCF service that one working fine. I am not sure that issue. Please help. i have enclosed my full code. please any one check and give me exact solution.
WCF – SERVICE CODE
Imports System.Data
Imports System.Configuration
Imports System.ServiceModel
Imports System.Runtime.Serialization
Imports System.Exception
Imports MySql.Data.MySqlClient
Public Class Service1
Implements IService
'Public Sub New()
'End Sub
Public objDBQueryClass As New DBQueryClass
''' <summary>
''' Check Login
''' </summary>
''' <param name="struserid"></param>
''' <param name="strpassword"></param>
''' <returns></returns>
Public Function GetLoginInfo(ByVal struserid As String, ByVal strpassword As String) As UserData Implements IService.GetUserLogin
Dim constr As String = "server=127.0.0.1;uid=root;pwd=1235;database=ABC;"
Using con As New MySqlConnection(constr)
Using cmd As New MySqlCommand("SELECT FirstName, LastName FROM userdetails WHERE UserId ='" & struserid & "' And Password = '" & strpassword & "'")
Using sda As New MySqlDataAdapter()
cmd.Connection = con
sda.SelectCommand = cmd
Using dt As New DataTable()
Dim customers As New UserData()
sda.Fill(customers.GetLoginInfo)
Return customers
End Using
End Using
End Using
End Using
End function
<ServiceContract()>
Public Interface IService
<OperationContract()>
Function GetUserLogin(ByVal struserid As String, ByVal strpassword As String) As UserData
<DataContract()>
Public Class UserData
Private Property CustomersTable As DataTable
Public Sub New()
Me.CustomersTable = New DataTable("CustomersData")
End Sub
<DataMember()>
Public Property GetLoginInfo() As DataTable
Get
Return CustomersTable
End Get
Set(value As DataTable)
CustomersTable = value
End Set
End Property
End Class
SERVER SIDE WEB.CONFIG
<?xml version="1.0"?>
<system.web>
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
</system.webServer>
XAMARAIN CLIENT SIDE CODE
using ServiceReference;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.ServiceModel;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
namespace MobileApp
{
public partial class MainPage : ContentPage
{
private ServiceClient client;
public static readonly EndpointAddress EndPoint = new EndpointAddress("http://127.0.0.1:50760/Service.svc");
public MainPage()
{
InitializeComponent();
InitilizeService1Client();
Init();
this.client = new ServiceClient();
}
private void InitilizeService1Client()
{
BasicHttpBinding binding = CreateBasicHttp();
client = new ServiceClient(binding, EndPoint);
}
private static BasicHttpBinding CreateBasicHttp()
{
BasicHttpBinding binding = new BasicHttpBinding
{
Name = "basicHttpBinding",
MaxBufferSize = 2147483647,
MaxReceivedMessageSize = 2147483647
};
TimeSpan timeout = new TimeSpan(0, 0, 30);
binding.SendTimeout = timeout;
binding.OpenTimeout = timeout;
binding.ReceiveTimeout = timeout;
return binding;
}
void Init()
{
BackgroundColor = ClassFiles.Constants.BackgroundColor;
Header.TextColor = ClassFiles.Constants.MainTextColor;
ActivitySpinner.IsVisible = false;
LoginIcon.HeightRequest = ClassFiles.Constants.LoginIconHeight;
EntryUserName.Completed += (s, e) => EntryPassword.Focus();
EntryPassword.Completed += (s, e) => SignInProcedure(s, e);
}
private async void SignInProcedure(object sender, EventArgs e)
{
ClassFiles.UserLogin user = new ClassFiles.UserLogin(EntryUserName.Text, EntryPassword.Text);
if (user.checkInformation())
{
await Navigation.PushModalAsync(new MainMasterDetailPage());
}
else
{
await DisplayAlert("login", "Login Not Correct, empty username or password,", "ok");
}
}
}
}
using Xamarin.Forms;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Collections;
using System.Reflection;
using System.Threading.Tasks;
using System.Data;
using System.Net.Http;
using System.Net;
namespace MobileApp.ClassFiles
{ class UserLogin
{
private string entryUserName;
private string entryPassword;
public UserLogin(string entryUserName, string entryPassword)
{
this.entryUserName = entryUserName;
this.entryPassword = entryPassword;
}
internal bool checkInformation()
{
if (NetworkCheck.IsInternet())
{
ServiceReference.IService MyClient = new ServiceReference.ServiceClient();
ServiceReference.UserData emp = new ServiceReference.UserData();
emp = MyClient.GetUserLoginAsync(entryUserName, entryPassword);
DataTable dt = new DataTable();
dt = emp.GetLoginInfo(entryUserName, entryPassword);
IF(dt.rows.count > 0)
{
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
}
}