同じソリューションで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();
}