locked
How to connect remote database(MS SQL Management studio) With Xamarin forms using ASP .NET C#? RRS feed

  • Question

  • User393719 posted

    Hello , I'm new to Mobile App's. Please help me in how to connect remote database(MS SQL Management studio) With Xamarin forms using ASP .NET C#? I've searched a lot but unable to find the required solution. Please help me out. Thanks in advance

    Thursday, April 23, 2020 8:54 AM

All replies

  • User74 posted

    Have you created your asp.net webapi yet? Start there, then look at how to call the webapi from Xamarin.

    Saturday, April 25, 2020 6:20 AM
  • User393719 posted

    Hello, I have already created a WCF Webservice, but I'm not getting how to consume it in Xamarin forms and display the results in andriod emulator. Please help Thanks

    Saturday, April 25, 2020 11:06 AM
  • User393719 posted

    Hello, Below is the code which im using for creating a WCF Webservice.

    //code for Service1.svc.cs public class Service1 : IService1 { private string conStr = "Data Source=Test; Initial Catalog=db; User ID=sa; Password=**"; public List Getusername() { List userlist = new List(); SqlConnection connection = new SqlConnection(this.conStr); connection.Open(); SqlCommand cmd = new SqlCommand("select username from admin", connection); cmd.CommandType = CommandType.Text; SqlDataReader sdr = cmd.ExecuteReader(); while (sdr.Read()) { username brand = new username(); brand.Name = sdr["username"].ToString(); userlist.Add(brand); } return userlist.ToList(); } }

    //code for IService1.cs [ServiceContract] public interface IService1 {

        [OperationContract]
        [WebGet(UriTemplate = "Getusername")]
        List<username> Getusername();
    
    }
    [DataContract]
    public class username
    {
        string brand;
        [DataMember]
        public string Name
        {
            get { return brand; }
            set { brand = value; }
        }
    
    }
    

    Please help me how to call this webservice in Xamarin forms and show the results in android emulator using asp .net c# Thanks

    Saturday, April 25, 2020 1:11 PM
  • User393719 posted

    Hello , Im getting error in below code after consuming a WCF Webservice in my Xamarin form.

    using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Linq; using System.Runtime.CompilerServices; using System.ServiceModel; using System.Text; using System.Threading.Tasks; using Xamarin.Forms;

    namespace App13 { public partial class MainPage : INotifyPropertyChanged { private static EndpointAddress endPoint = new EndpointAddress("http://192.168.34.242:80/Service1.svc"); private static BasicHttpBinding binding; public MainPage() { InitializeComponent(); binding = CreateBasicHttpBinding(); } private static BasicHttpBinding CreateBasicHttpBinding() { 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;
        }
        public class details
        {
            public string username { get; set; }
        }
        //public async static Task<List<details>> Getusername()
        //{
        //    try
        //    {
        //        ServiceReference1.IService1 service1 = new ServiceReference1.Service1Client();
        //        var result = await service1.GetusernameAsync();
        //        return result;
        //    }
        //    catch (Exception)
        //    {
        //        throw;
        //    }
        //}
        private List<details> _adminList;
    
        public List<details> EmployeesList
        {
            get
            {
                return _adminList;
            }
            set
            {
                _adminList = value;
                OnPropertyChanged();
            }
    
        }
        private async Task InitializeDataAsync()
        {
            ServiceReference1.IService1 service1 = new ServiceReference1.Service1Client();
            var employees = await service1.GetusernameAsync();
    
            EmployeesList = new ObservableCollection<details>(employees);
        }
        public event PropertyChangedEventHandler PropertyChanged;
    
        protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
    }
    

    } Please help , I wanted to bind the webservice to listview in xamarin form(cross platform) and didplay the same in mobile please help Thanks

    Sunday, April 26, 2020 10:19 AM
  • User393719 posted

    Please help me

    Sunday, May 3, 2020 4:04 AM