Hello Sir,
I'm new to development and WCF Web services.
I'm getting below error after consuming WCF web services in my Xamarin cross platform project.
Error CS1061 'Task' does not contain a definition for 'ToList' and no accessible extension method 'ToList' accepting a first argument of type 'Task' could be found (are you missing a using directive or an assembly reference?) WCF_LoginApp
Code for Service1.svc.cs
- using System;
- using System.Collections.Generic;
- using System.Data.SqlClient;
- using System.Linq;
- using System.Runtime.Serialization;
- using System.ServiceModel;
- using System.ServiceModel.Web;
- using System.Text;
- namespace ServiceLogin
- {
- // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
- // NOTE: In order to launch WCF Test Client for testing this service, please select Service1.svc or Service1.svc.cs at the Solution Explorer and start debugging.
- public class Service1 : IService1
- {
- public List<string> LoginUserDetails(UserDetails userInfo)
- {
- List<string> usr = new List<string>();
- SqlConnection con = new SqlConnection("Data Source=Test; Initial Catalog=crm_db; User ID=sa; Password=*****");
- con.Open();
- SqlCommand cmd = new SqlCommand("select username,password from crm_tbl_admin where username=@UserName and password=@Password", con);
- cmd.Parameters.AddWithValue("@UserName", userInfo.UserName);
- cmd.Parameters.AddWithValue("@Password", userInfo.Password);
- SqlDataReader dr = cmd.ExecuteReader();
- if (dr.Read() == true)
- {
- usr.Add(dr[0].ToString());
- }
- con.Close();
- return usr;
- }
- }
- }
Code for consuming the above service in my MainPage.Xaml.cs
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Xamarin.Forms;
- using ServiceReference1;
- using System.ServiceModel;
- namespace WCF_LoginApp
- {
- public partial class MainPage : ContentPage
- {
- Service1Client obj = new Service1Client();
- private static EndpointAddress endPoint = new EndpointAddress("http://localhost/ServiceLogin/Service1.svc");
- private static NetTcpBinding binding;
- public MainPage()
- {
- InitializeComponent();
- binding = CreateBasicHttpBinding();
- }
- private static NetTcpBinding CreateBasicHttpBinding()
- {
- NetTcpBinding binding = new NetTcpBinding
- {
- Name = "netTcpBinding",
- MaxBufferSize = 2147483647,
- MaxReceivedMessageSize = 2147483647
- };
- TimeSpan timeout = new TimeSpan(0, 0, 30);
- binding.SendTimeout = timeout;
- binding.OpenTimeout = timeout;
- binding.ReceiveTimeout = timeout;
- return binding;
- }
- private void BtnLogin_Clicked(object sender, EventArgs e)
- {
- try
- {
- UserDetails userinfo = new UserDetails();
- userinfo.UserName = usernameEntry.Text;
- userinfo.Password = passwordEntry.Text;
- List<string> msg = obj.LoginUserDetailsAsync(userinfo).ToList();
- //var result = obj.LoginUserDetailsAsync(userinfo);
- //string msg = result.ToString();
- messageLabel.Text = "Employee Name = " + msg.ElementAt(0);
- }
- catch (Exception ex)
- {
- // messageLabel.Text = "Wrong Id Or Password";
- throw ex;
- }
- }
- }
- }
The code for Webconfig for WCF project is below
- "1.0"?>
"aspnet:UseTaskFriendlySynchronizationContext" value="true" />"true" targetFramework="4.6.1" />"4.6.1" />"true" httpsGetEnabled="true"/>"false" />"ServiceLogin.Service1" >"Service1" contract="ServiceLogin.IService1" binding="wsHttpBinding" />"Service1" binding="netTcpBinding" contract="ServiceLogin.IService1"/>"http://localhost:8080/" />"net.tcp://localhost:8090/" />"wsHttpBinding" scheme="http" />"netTcpBinding" scheme="net.tcp"/>"true" multipleSiteBindingsEnabled="true" />"true" />"true" />
Please help
Thanks in advance
Demo CloudPosted May 5, 2020, 12:47 AM
Demo CloudPosted May 4, 2020, 3:30 AM
Demo CloudPosted May 4, 2020, 3:09 AM
Demo CloudPosted May 2, 2020, 5:16 AM
Salman BegPosted May 2, 2020, 4:55 AM
Demo CloudPosted May 2, 2020, 4:50 AM
Salman BegPosted May 2, 2020, 4:46 AM