ASP.net 페이지에서 WCF 서비스를 사용하는 데 좋은 패턴을 조언 할 수있는 사람이 있습니까? 클라이언트 (: ServiceModel.ClientBase)의 수명이 적절하게 제어되지 않아서 PipeException이 발생하는 것으로 보입니다. 현재 Page 클래스의 필드로 존재하지만 정리되지 않고 각 페이지 요청시 다시 인스턴스화됩니다 (.Close 메소드).ASP.net의 WCF 클라이언트 페이지
이 질문은 "ASP.net 페이지의 제한된 리소스 관리"라고 바꿔서 ASP.net 페이지의 수명주기와 더 관련이 있다고 생각됩니다. ASP.net을 처음 접했으므로이 점에 대한 나의 이해는 다소 희박합니다.
TIA.
편집 : 일부 코드 (! 그것을 많지 않다)
public partial class Default : Page
{
//The WCF client... obviously, instantiating it here is bad,
//but where to instantiate, and where to close?
private readonly SearchClient client = new SearchClient();
protected void Page_Load(object sender, EventArgs e)
{
2 편집 : 다음은 더 나은 것인가?
public partial class Default : Page
{
private SearchClient client;
protected void Page_Unload(object sender, EventArgs e)
{
try
{
client.Close();
}
catch
{
//gobbled
}
}
protected void Page_Load(object sender, EventArgs e)
{
client= new SearchClient();
//.....
당신은 코드 샘플을 제공 할 수 있습니까? – bendewey