WCF服务 - notimplementedexception

时间:2011-12-12 10:51:36

标签: c# asp.net wcf notimplementedexception

我正在练习在同一解决方案中使用WCF和两个项目。该服务应该从northwnd db获取信息,客户端显示它。

在我向界面/合约GetSelectedCustomer(string companyName)添加新方法存根之前,一切正常。

我已经实现了界面(使用智能标签确定)。一切都编好了。但是,当从客户端的代码隐藏调用该方法时,它会抛出NotImplementedException

我发现的唯一看起来奇怪的是,在intellisense中,GetSelectedCustomer的图标是内部方法的图标,而其他图标则具有通常的公共方法图标。我不确定为什么会这样。

我的界面:

[ServiceContract(Namespace = "http://localhost/NorthWndSrv/")]
public interface INorthWndSrv
{
    [OperationContract]
    Customer GetSingleCustomer(string custID);

    [OperationContract]
    Customer GetSelectedCustomer(string companyName);

    [OperationContract]
    List<Customer> GetAllCustomers();

    [OperationContract]
    List<string> GetCustomerIDs();
}

[DataContract]
public partial class Customer
{
    [DataMember]
    public string Company { get; set; }
    [DataMember]
    public string Contact { get; set; }
    [DataMember]
    public string CityName { get; set; }
    [DataMember]
    public string CountryName { get; set; }
}

实施:

public class NorthWndSrv: INorthWndSrv
{
    public Customer GetSingleCustomer(string custID)
    {
        //stuff that works
    }

    public List<Customer> GetAllCustomers()
    {
        //stuff that works
    }

    public List<string> GetCustomerIDs()
    {
        //stuff that works 
    }

    public Customer GetSelectedCustomer(string companyName)
    {
        using (northwndEntities db = new northwndEntities())
        {
            Customer c = (from cust in db.CustomerEntities
                          where cust.CompanyName == companyName
                          select new Customer
                          {
                              Company = cust.CompanyName,
                              Contact = cust.ContactName,
                              CityName = cust.City,
                              CountryName = cust.Country
                          }).FirstOrDefault();
            return c;
        }
    }
}

页面代码隐藏中的GridView事件:

protected void GridViewCustomers_SelectedIndexChanged(object sender, EventArgs e)
{
    NorthWndServiceReference.NorthWndSrvClient Service = new NorthWndServiceReference.NorthWndSrvClient();
    string companyName = GridViewCustomers.SelectedRow.Cells[2].Text; //company name
    NorthWndServiceReference.Customer cust = Service.GetSelectedCustomer(companyName);
    ArrayList custList = new ArrayList();
    custList.Add(cust);
    DetailsViewCustomers.DataSource = custList;
    DetailsViewCustomers.DataBind();      
}

1 个答案:

答案 0 :(得分:5)

听起来您的服务正在调用实现程序集的过时版本。尝试清理项目,然后重建。

特别是,如果您正在使用依赖项注入容器,并且项目中没有显式引用到实现GetSelectedCompany的程序集,则可能无法看到程序集的更新版本。添加显式引用或创建其他方式(例如构建后任务)将程序集复制到正确的位置。