0

同じソリューションで2つのプロジェクトでWCFを使用する練習をしています。サービスはnorthwnddbから情報を取得することになっており、クライアントはそれを表示します。

インターフェイス/コントラクトに新しいメソッドスタブを追加するまで、すべてが正常に機能していました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();      
}
4

1 に答える 1

5

サービスが古いバージョンの実装アセンブリを呼び出しているようです。プロジェクトをクリーンアップしてから、再構築してみてください。

特に、依存性注入コンテナを使用していて、プロジェクトに実装されているアセンブリへの明示的な参照がGetSelectedCompanyない場合は、アセンブリの更新されたバージョンが表示されない可能性があります。明示的な参照を追加するか、他の方法(ビルド後のタスクなど)を作成して、アセンブリを適切な場所にコピーします。

于 2011-12-12T11:06:05.867 に答える