WCF requesting an array of objects

I am still working on a WCF solution that should be able to query the backend of the program and return the results.

The backend stores a dictionary of objects with the name Groups , and they can be requested using functions such as:

  • GetGroup to get a separate group by ID
  • GetGroups to get a list of groups by tags.

GetGroup works great with the WCF test client and the application I created. And it works with the following application form code:

  List<string> values = new List<string>(); GroupServiceClient client = new GroupServiceClient("WSHttpBinding_IGroupService"); www.test.co.uk.programme.programme Group = new www.test.co.uk.programme.programme(); DateTime time = DateTime.Now; values.Clear(); client.Open(); Group.number = textBox1.Text; client.GetGroup(ref time, ref Group); GroupStorageMessage toReturn = new GroupStorageMessage(); toReturn.group = Group; selectedGroupId = Convert.ToString(toReturn.group.number); values.Add(Convert.ToString(toReturn.group.number)); values.Add(Convert.ToString(toReturn.group.name)); listBox1.ItemsSource=values; client.Close(); 

GetGroups works great with the WCF test client, but not with my application.

It sends the request as it should, but returns Null (note that this code forms another application, and Im uses the link instead of the proxy file)

  ServiceReference1.programme Group = new ServiceReference1.programme(); ServiceReference1.GroupServiceClient Client = new ServiceReference1.GroupServiceClient(); DateTime Time = DateTime.Now; Client.Open(); string[] aa = new string[1]; aa[0] = textBox1.Text; Group.tags = aa; Client.GetGroups(ref Time, Group); ServiceReference1.GroupArrayMessage toReturn = new ServiceReference1.GroupArrayMessage(); ServiceReference1.programme[] Groups = new ServiceReference1.programme[1]; toReturn.groups = Groups; = returns null 

in the new program ServiceReference1.programme [1]; I really know what to put there.

Interface:

 [ServiceContract(Namespace = "http://www.Test.co.uk/groupstorage")] public interface IGroupStorageService { /** * Get a group from the collection of groups */ [OperationContract] GroupStorageMessage GetGroup(GroupStorageMessage message); /** * Add a group to the collection of groups */ [OperationContract] void AddGroup(GroupStorageMessage message); /** * Remove a group from the collection of groups */ [OperationContract] void RemoveGroup(GroupStorageMessage message); /** * Update a group in the collection of groups */ [OperationContract] void UpdateGroup(GroupStorageMessage message); [OperationContract] GroupArrayMessage GetGroups(GroupStorageMessage message); } 

Message:

 [MessageContract] public class GroupArrayMessage { /** * Message header is the timestamp when the message was created */ [MessageHeader(Name = "time")] public DateTime Time; /** * Message body is a collection of Users */ [MessageBodyMember(Name = "groups")] public Group[] Groups; } 

Group contact (sometimes called a program)

 [DataContract(Namespace = "http://www.test.co.uk/programme", Name = "programme")] public class Group { /** * The number representing the Programme (Programme ID) */ [DataMember(Name = "number")] public string Number; /** * The name of the Programme */ [DataMember(Name = "name")] public string Name; /// <summary> /// Add Tags /// </summary> [DataMember(Name = "tags")] public string[] Tags; 
+6
source share
1 answer

Finally, I found a solution:

  GroupService.GroupArrayMessage toReturn = new GroupService.GroupArrayMessage(); GroupService.programme[] Groups = Client.GetGroups(ref Time, Group); toReturn.groups = Groups; listBox1.ItemsSource = toReturn.groups; 
+4
source

Source: https://habr.com/ru/post/912863/


All Articles