Question

I'm practicing using WCF with two projects in the same solution. The service is supposed to get info from the northwnd db, and the client displays it.

Everything was working ok until I added a new method stub to my interface/contract, GetSelectedCustomer(string companyName).

I've implemented the interface (using the smart tag to be certain). Everything compiles ok. However when the method is called from the client's code-behind it throws a NotImplementedException.

The only thing I've found that looks odd is that, in intellisense, the icon for GetSelectedCustomer is that of an internal method, while the others have the usual public method icons. I'm not certain why that is.

My interface:

[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; }
}

The implementation:

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;
        }
    }
}

The GridView Event in the page's code-behind:

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();      
}
Était-ce utile?

La solution

It sounds like your service is calling an out-of-date version of the implementation assembly. Try cleaning the project, then rebuilding.

In particular, if you're using a dependency injection container and don't have an explicit reference in your project to the assembly where GetSelectedCompany is implemented you may well not see the updated version of the assembly. Either add an explicit reference or create some other way (e.g. a post-build task) to copy the assembly to the right place.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top