6

我仍在研究应该能够查询程序后端并返回结果的 WCF 解决方案。

后端存储了一个调用对象的字典,Groups可以使用以下函数查询它们:

  • GetGroup通过 ID 获取单个组
  • GetGroups按标签获取组列表。

GetGroupWCF 测试客户端和我构建的应用程序可以正常工作。它适用于应用程序的以下代码:

        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与 WCF 测试客户端完美配合,但不适用于我的应用程序。

它按应有的方式发送查询,但确实返回Null(请注意,此代码来自另一个应用程序,我使用的是引用而不是代理文件)

        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

在新的 ServiceReference1.programme[1] 中;我实际上在猜测要放什么。

界面:

[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);
}

消息合约:

[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;
}

团体联系(有时称为计划)

[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;
4

1 回答 1

4

我终于找到了解决方案:

        GroupService.GroupArrayMessage toReturn = new GroupService.GroupArrayMessage();


        GroupService.programme[] Groups = Client.GetGroups(ref Time, Group);

        toReturn.groups = Groups;

        listBox1.ItemsSource = toReturn.groups;
于 2012-04-19T15:00:01.397 回答