2011-02-10 2 views
3

:System.ServiceModel.ClientBase를 처리하는 방법 <TChannel>? 내가 ClientBase <>를 확장하는 클래스를 사용하고

interface IService {} 
class MyServiceClient : ClientBase<IService> {} 

내가으로 실행하는 문제는합니다 FxCop는 멤버 변수로 MyServiceClient와 클래스도는 IDisposable을 구현하고 MyServiceClient 폐기해야한다는 불평이다.

ClientBase에는 Dispose()가 명시 적으로 구현되어있어 간단한 MyServiceClient.Dispose()가 컴파일되지 않음을 의미합니다. 나는 IDisposable에 명시 적으로 캐스트해야합니다. 왜 그런가요? Dispose()를 사용하지 말아야한다는 신호입니까? 대신 Close()를 사용해야합니까?

답변

4

Close and Dispose - which to call?에는 Close와 Dispose가 동일한 구현을 가져야한다고 제안되었습니다. Here은 Dispose 함수에서 Close를 호출하는 예제 래퍼 클래스 (usage)입니다. 따라서 Close를 호출하는 것이 좋습니다.

0

필자의 Base inheritor를 bloc을 사용하여 감쌌다. 이처럼 :

using (var someClient = new SomeClient(_netTcpBinding,_endpointAddress)) 
{ 
    return someClient.SomeMethod(); 
} 

을하지만 난 enter image description here

여기 http://sahilmalik.blogspot.ru/2005/11/sockets-and-timewait.html 발견 대답을보고 나는이 경우 http://marcgravell.blogspot.ru/2008/11/dontdontuse-using.html에서처럼 내 코드를 재 작성에서 netstat -a -n -p TCP를 cmd를 열고 다음을 입력 할 때

관련 문제