首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >WCF服务- notimplementedexception

WCF服务- notimplementedexception
EN

Stack Overflow用户
提问于 2011-12-12 18:51:36
回答 1查看 884关注 0票数 0

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

一切正常,直到我在我的接口/契约中添加了一个新的方法存根,GetSelectedCustomer(string companyName)

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

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

我的界面:

代码语言:javascript
复制
[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; }
}

实现:

代码语言:javascript
复制
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事件:

代码语言:javascript
复制
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();      
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-12-12 19:06:06

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

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

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8473164

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档