我有一个包含所有品牌列表的组合框,我需要将组合框的这个选定值传递给名为 service1.svc 的 wcf 服务。我无法理解如何将所选项目作为参数传递给服务。你们能不能帮帮我。谢谢
我的服务参考如下
命名空间 SilverlightApplication2.Web {
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.xaml.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());
}
}
}
我得到对象引用未设置为对象的实例。在 var proxy = new Service1Client(selectedItem.ToString());