【问题标题】:WCF Service - notimplementedexceptionWCF 服务 - 未实现的异常
【发布时间】:2011-12-12 10:51:36
【问题描述】:

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

一切正常,直到我向我的接口/合同添加了一个新的方法存根 GetSelectedCustomer(string companyName)

我已经实现了接口(使用智能标签来确定)。一切编译正常。但是,当从客户端的代码隐藏调用该方法时,它会抛出一个NotImplementedException

我发现唯一看起来很奇怪的是,在智能感知中,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();      
}

【问题讨论】:

  • GetSelectedCompany 在哪里?您如何引用服务(也许您只需要更新 Web 服务)
  • 抱歉,应该阅读 GetSelectedCustomer。我已经编辑了帖子以反映这一点。我在 Web 应用程序项目中添加了对服务的引用,并在 SelectedIndexChanged 事件的第一行创建了它的一个实例。由于某种原因,它的颜色是绿色的
  • OK .. 你有没有尝试我评论的第二部分,更新服务?
  • 我已经构建并重建了这两个项目,恐怕没有任何运气。

标签: c# asp.net wcf notimplementedexception


【解决方案1】:

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

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

【讨论】:

  • 再次重建,清理,然后重新添加服务引用。现在工作正常。谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2010-12-25
  • 2014-11-09
  • 2010-12-11
  • 2012-09-20
  • 1970-01-01
  • 1970-01-01
  • 2017-06-13
相关资源
最近更新 更多