Search code examples
c#linqwcfserviceserver

(Service) program freeze when getting an object from Service


Hello everyone i keep getting this problem, and i dont get any specific error message.

its is a minesweeper game project.

i can log in, and see the list of all logged in players in a listbox. that works fine.

the service's method also works fine. in debug mode it returns the wanted object of type "MsServer300.User" to the client's method, and the next line to execute is now back in the client's method and there it freezes. (MsServer300 is the name of the Project that contains the service). the class "User" is from a database that is connected to the service.

Any ideas why? Thanks!!

this is the client method:( it is long for error searching reasons )

private void listBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { ///////////
        try
        {
            MsServiceClient proxy = new MsServiceClient(new InstanceContext(Callback));
            string s = LbConnectedPlayers.SelectedItem.ToString();

            var userDetails = proxy.GetDetails(s);  //<<<here is the error  
            if (userDetails == null)
                MessageBox.Show("user details is null");
            else
            LbConnectedPlayers.ItemsSource = userDetails.ToString();
        }catch(Exception ex){
            MessageBox.Show("error in selectionchange    "+ex.Message);
        }

    }

this is the service method :

        public User GetDetails(string name)
    {
        try
        {
            using (ms_AvishayAndRonen6Entities ctx = new ms_AvishayAndRonen6Entities())
            {
                //User user = ctx.Users.SingleOrDefault(a => a.UserName == name);
                //return user;
                User user = (from m in ctx.Users
                           where m.UserName == name
                           select m).First();
                return user;
            }
        }
        catch (Exception ex)
        {
            User exUser = new User();
            exUser.UserName = ex.Message;
            return exUser;
        }

    }

Solution

  • I am not seeing the connection details, but I always set the Multiple Active Results Sets to True. Try that and see if that fixes your problem. here is a connection string example:

    using System.Data.SqlClient;
    
    namespace MyConnection
    {
    class Connection
    {
    
      public static SqlConnection GetConnection()
      {
            string connectionString = "Data Source=WhateverYourdataSource;Initial Catalog=EDI;Persist Security Info=True;User ID=YourID;Password=Password.is;Integrated Security=False;MultipleActiveResultSets=True";
            SqlConnection connection = new SqlConnection(connectionString);
            return connection;
        }
    
    }
    }