将组合框选择的值传递给WCF以从silverlight 5 Pivot Viewer客户端获取数据

本文关键字:Pivot silverlight Viewer 客户端 数据 获取 以从 WCF 选择 组合 值传 | 更新日期: 2023-09-27 18:18:23

我有一个包含所有品牌列表的组合框,我需要将这个组合框的选定值传递给名为service1.svc的wcf服务。我无法理解如何将选中的项目作为参数传递给服务。你们能帮帮我吗。由于

我的服务参考如下

SilverlightApplication2

名称空间。网络{

public class Service1
{
    [OperationContract]
    public ObservableCollection<Employee> GetAllEmployees(string brandID)  
    {
        var emps = new ObservableCollection<Employee>();
        string connect = ConfigurationManager.ConnectionStrings["yoyo"].ToString();
        using(var con = new OdbcConnection(connect))
        {

            string query = "Select new,brand,imagelink FROM pivottable WHERE brand='"+brandID+"'";

            var cmd = new OdbcCommand(query, con);

            con.Open();

            using (var dr = cmd.ExecuteReader())
            {
                while(dr.Read())
                {
                    var emp = new Employee();
                    emp.EmployeeID = dr.GetInt32(0);
                    emp.FirstName = dr.GetString(1);
                    emp.ImageURI = new Uri(dr.GetString(2));
                    emps.Add(emp);
                }

            }

        }
        return emps; 
    }

}

}

我的mainpage. example .cs如下

SilverlightApplication2

名称空间{

   public partial class MainPage : UserControl
{
   public MainPage()
    {
        InitializeComponent();
        object selectedItem = Combobox.SelectedItem;
        var proxy = new Service1Client(selectedItem.ToString());
      //  var proxy = new Service1Client();
        proxy.GetAllEmployeesCompleted += proxy_GetAllEmployeesCompleted;
       proxy.GetAllEmployeesAsync();
       var proxytwo = new Service1Client();
       proxytwo.GetAllBrandsCompleted += proxytwo_GetAllBrandsCompleted;
       proxytwo.GetAllBrandsAsync();
    }
    void proxytwo_GetAllBrandsCompleted(object sender, GetAllBrandsCompletedEventArgs f)
    {
        Combobox.ItemsSource = f.Result;
    }

    void proxy_GetAllEmployeesCompleted(object sender,GetAllEmployeesCompletedEventArgs e)
    {

        Pivot.ItemsSource = e.Result;

    }
        private void btnAdd_Click(object sender, RoutedEventArgs e)
    {
        object selectedItem = Combobox.SelectedItem;
        MessageBox.Show("Selected item is" +selectedItem.ToString());
    }

}

}

我得到的对象引用没有设置为对象的实例。at var proxy = new Service1Client(selecteitem . tostring ());

将组合框选择的值传递给WCF以从silverlight 5 Pivot Viewer客户端获取数据

var proxy = new Service1Client();
proxy.GetAllEmployeesCompleted += proxy_GetAllEmployeesCompleted;
proxy.GetAllEmployeesAsync(selectedItem.ToString());

如果你在最后一行得到编译器错误,你需要更新你的服务代理。右键单击服务引用,选择ide语言中最接近"Update"的内容