0

I want to populate a Datagrid with some items from database through WCF Service when window is loaded or user click a button, but I receive the following message:

enter image description here

enter image description here

What is wrong ?

here is my code from WCF :

 public IEnumerable<sesizari> getSesizari()
      {
          try
          {
           IEnumerable<sesizari> query = from sel in dataP.sesizaris select sel;
           return query;
           
          }
          catch(FaultException ex)
              {
              throw ex;
              }
      }

Client code :

  private void Service_Window_Loaded(object sender, RoutedEventArgs e)
        {
          try  {

            GridView gridView = new GridView();
           SesizariList.View = gridView;
            gridView.Columns.Add(new GridViewColumn
            {
                Header = "Id Sesizare",
                DisplayMemberBinding = new Binding("id_sesizare")
            });
            gridView.Columns.Add(new GridViewColumn
            {
                Header = "Titlu",
                DisplayMemberBinding = new Binding("titlu"),

            });
            gridView.Columns.Add(new GridViewColumn
            {
                Header = "Client",
                DisplayMemberBinding = new Binding("client"),

            });
           
            SesizariList.ItemsSource = client.getSesizari();
            SesizariList.Items.Refresh();
      }
catch(Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
        }

I've enabled trace logging and the problem is at getSesizari() method, but I don't know what is wrong...

There was an error while trying to serialize parameter http://tempuri.org/:getSesizariResult.
 The InnerException message was 'Type 'System.Data.Entity.DynamicProxies.sesizari_3A8E1D8187ED0306632025D5E2C490F13F4A3E7EF93AFE8F6B9C7DE55AFA8511'
 with data contract name sesizari_3A8E1D8187ED0306632025D5E2C490F13F4A3E7EF93AFE8F6B9C7DE55AFA8511:http://schemas.datacontract.org/2004/07/System.Data.Entity.DynamicProxies' 
is not expected. Consider using a DataContractResolver or add any types not known statically to the list of known types - for example,
 by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.'. 
 Please see InnerException for more details.
BMA
  • 33
  • 6
  • Where is your wcf service hosted? Can you debug it? If so does your request reach the server at all? It looks like it doesn't. This can happen due to many reasons like web service config issues, network issues etc. On a side note, you need to close/dispose your client. Better to initialise the client within using(var client = new MyClient()){//call the service} – Kosala W Nov 13 '15 at 06:19
  • WCF service is locally hosted . Also I see this exception when I debug it : `Inner Exception: An existing connection was forcibly closed by the remote host at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags) at System.ServiceModel.Channels.SocketConnection.ReadCore(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout, Boolean closing)` – BMA Nov 14 '15 at 05:41
  • What did you debug? Did you debug the WCF service as I suggested? – Kosala W Nov 14 '15 at 05:42
  • I've debug both client and WCF service and I've noticed that something it's wrong with my query because it's show the following message: `Results View Function evaluation disabled because a previous function evaluation timed out. You must continue execution to reenable function evaluation. ` If I delete all data from that table the fault exception disapear – BMA Nov 14 '15 at 06:35
  • Ok. So now it's clear that the issue is in your server side. You were seeing your previous exception on your client side because of the server side bug. Hope that helped you to find the root cause and rectify the issue. – Kosala W Nov 14 '15 at 06:44

1 Answers1

0

Problem solved... issue was in getSesizari() method, because EntityFramework create a 'proxy' of the class . Solution was to set ContextOptions.ProxyCreationEnabled = false; in the Context constructor.

DataContractSerializer Error using Entity Framework 4.0

Community
  • 1
  • 1
BMA
  • 33
  • 6