반응형
WCF에 대한 코드에서 IncludeExceptionDetailInFaults를 true로 설정합니다.
App.Config를 사용하지 않고 코드에서 IncludeExceptionDetailInFaults를 어떻게 설정합니까?
예, 물론입니다-서비스 호스트를 열기 전에 서버 측에서. 그러나 이렇게하려면 WCF 서비스를 자체 호스팅해야합니다. IIS 호스팅 시나리오에서는 작동하지 않습니다.
ServiceHost host = new ServiceHost(typeof(MyWCFService));
ServiceDebugBehavior debug = host.Description.Behaviors.Find<ServiceDebugBehavior>();
// if not found - add behavior with setting turned on
if (debug == null)
{
host.Description.Behaviors.Add(
new ServiceDebugBehavior() { IncludeExceptionDetailInFaults = true });
}
else
{
// make sure setting is turned ON
if (!debug.IncludeExceptionDetailInFaults)
{
debug.IncludeExceptionDetailInFaults = true;
}
}
host.Open();
IIS 호스팅에서 동일한 작업을 수행해야하는 경우 이러한 사용자 지정 서비스 호스트를 인스턴스화 MyServiceHost
하는 고유 한 사용자 지정 하위 항목과 적합한 항목 을 만들고 MyServiceHostFactory
* .svc 파일에서이 사용자 지정 서비스 호스트 팩토리를 참조해야합니다.
인터페이스를 상속하는 클래스 선언 위의 [ServiceBehavior] 태그에서 설정할 수도 있습니다.
[ServiceBehavior(IncludeExceptionDetailInFaults = true)]
public class MyClass:IMyService
{
...
}
반응형
'Program Tip' 카테고리의 다른 글
UI 스레드에서 강제로 GUI 업데이트 (0) | 2020.11.04 |
---|---|
SVN 작업 카피 레이아웃 버전을 어떻게 결정합니까? (0) | 2020.11.04 |
SqlAlchemy를 사용하여 ID로 데이터베이스를 쿼리하는 방법은 무엇입니까? (0) | 2020.11.04 |
maven : 명령 줄 옵션 또는 env 변수를 사용하여 로컬 저장소의 위치를 재정의 할 수 있습니까? (0) | 2020.11.04 |
예외가 특정 유형인지 확인하는 방법 (0) | 2020.11.04 |