Click here to Skip to main content
15,885,309 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I cannot see the DataMember .. datas belonging to the DataService class from my winforms WCF Client, I can do the operations and that works fine - I just cannot see this DataMember object {datas} ; what am I doing wrong?

Below is the example code:

C#
    [DataContract]
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
    public class DataService : IDataService  
    {   // have tried this too [DataMember] on backing field. 	
        BindingList<Data> m_datas;        
        [DataMember]
	public BindingList<Data> datas 
	{
		get 
		{
		  if (this.m_datas == null) 
		  {
		     this.m_datas = new BindingList<Data>();
		  }
		    return this.m_datas;
		}
		set 
		{
		   m_datas = value;
		}
	}
}


My interface is
C#
[ServiceContract]
public interface IDataService
{
	[OperationContract]
	BindingList<Data> GetData();
}

[DataContract]
public class Data
{
   [DataMember]
   public string name;
}


The reason I want to do this; is that I have a service that is constantly running and monitoring - it then updates this internal list of objects, which I then want my client to show real time updates - I can show the data by using GetData but this requires me to handle this all the time whenever the list changes in the service. Isn't there a better way to do this ?
Posted
Updated 28-May-15 6:26am
v3
Comments
macika123 27-May-15 18:11pm    
Did you mark class Data also as DataContract and its members as DataMember like you did with DataService?
stixoffire 28-May-15 9:43am    
I added the class to the question, yes it is marked and for the life of me I am stumped as to why it is not there - I updated the reference as well - and it is still not showing up.
Mathi Mani 27-May-15 19:27pm    
Implementation seems wrong. Why are you marking Service implementation as [DataContract]?
stixoffire 28-May-15 9:35am    
I am trying to get the BindingList to show up in my client app, and so I marked it thinking I will see if the problem is between the chair and the code.
stixoffire 28-May-15 12:20pm    
OK so MSDN says I cannot have a DataMember in the service contract thanks for that hint that I am doing something wrong. Now I need to know how to reflect changes of this binding list back to my client - I was preferring not to do GetData repetitively. So I will need to know when that list changes and create a method to trigger an update of the client - I do not know how to have the WCF service update this object in a Winform automagically - unless I need to reference the application.MyObjectList some how to do this.

1 solution

Where do you want to access the datas property of your service? Does it in the client side? If so, It looks like there is a little misunderstanding of how the things works.


When you create a client to your service (using ChannelFactory or Add Service Reference), it creates an object that implements your ServiceContract (in your case: IDataService) and contains implementation for your OperationContracts - No properties are transfered.


If you want to get the value of datas, you should implement GetData to return it. You should declare the data (Data) as a DataContract (not the service...)

 
Share this answer
 
Comments
stixoffire 28-May-15 9:47am    
If I use GetData - then I physically need to request it when a change is made to the underlying component. I have a DataGridView that is bound to a datasource (which I do use GetData to fill that bindingsource - but when I add to this Datas - it is there but I do not get the changes reflected back in my DataGridView - so I am trying to bind my bindingsource to this component directly for the changes to be reflected in my client. Am I going about this wrong ?
stixoffire 28-May-15 12:56pm    
Maybe there is no way to do what I would like to do except to use a listchanged event in the service and trigger a WCFCallback that my Client can receive ??? Is that how I need to do this ? I have things working with GetData() but when the "datas" changes I want my Client DataGridView to reflect those changes in close proximity to real time - <200ms or so .
Shmuel Zang 28-May-15 14:42pm    
Sending callback to the client can be a good idea. See also about: WCF Duplex Services.
stixoffire 28-May-15 15:15pm    
I was expecting something similar to the bindingsource data changes - the DataGridView automagic update by binding to that list, As I have been reading WCF does not work so nice like that. II really do not want to get the whole datasource to send , but only changes so maybe I need to know what indexes in the list changed and send them on the callback and in the receive handle the changedevent . So then I need a better collection object where I can know what items are changed, added, modified , new - and I am thinking a DataTable would have all of that built in , so I do not need to roll my own stuff. Any thoughts as to if this is a good or bad idea ?
stixoffire 30-May-15 6:57am    
Is there a difference between duplex services and using callbacks? - they seem to be the same to me, and the example at the link is what I have implemented to test out. What is WCF Data services used for - does it do anything special for me that Duplex Services can't ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900