2011-04-26 2 views
3

WCF 서비스가 있고 IErrorHandler가 바인딩 된 FaultContract가 있는데 잘 작동했습니다. 어떤 이유로 런타임에 바인드되는 것을 중단했습니다. ApplyDispatchBehaviorValidate에 중단 점을 배치 할 때 디버깅을 시작할 때 중단 점을 지정합니다 (중지하는 데 사용함). 따라서 오류가 발생하면 예외가 처리되지 않습니다.
처음에는 this blog post을 따라 갔고 제대로 작동했지만 두 번째 인터페이스/엔드 포인트를 추가하면 작동이 멈췄습니다. this SO post에 따라 코드를 모두 변경했지만 아무런 효과가 없습니다. 내가 두 번째 엔드 포인트/인터페이스를 추가 한 후
IErrorHandler가 바인딩되지 않고 오류를 처리하지 않습니다.

The 'TestAppServer, Version 1.0.0.0, Culture=neutral, PublicKeyToken=null' assembly could not be found. Do you want to locate it? If you select 'No', you will not be prompted for the same assembly again. To avoid seeing this message every time the system cannot fund the assembly, please copy the assembly file to the same folder as the configuration file. 

이 오류가 위의 경우에 일어나는 시작 : 일이 시작 또 다른 것은 내가 Microsoft 서비스 구성 편집기에서 web.config를 열 때, 나는 오류가 발생한다는 것입니다 내 WCF 서비스에서 오류 처리를 잃었습니다. 다음은

namespace company.Test.appserver.implementation 
{ 
    public class ServiceErrorHandlerBehaviorExtensionElement : BehaviorExtensionElement, IServiceBehavior 
    { 
    public override Type BehaviorType 
    { 
     get { return typeof(TestErrorHandler); } 
    } 

    protected override object CreateBehavior() 
    { 
     return new TestErrorHandler(); 
    } 

    private IErrorHandler GetInstance() 
    { 
     return new TestErrorHandler(); 
    } 

    public void AddBindingParameters(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase, Collection<ServiceEndpoint> endpoints, BindingParameterCollection bindingParameters) 
    { 

    } 

    public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase) 
    { 
     IErrorHandler errorHandlerInstance = GetInstance(); 
     foreach (ChannelDispatcherBase cdb in serviceHostBase.ChannelDispatchers) 
     { 
     ChannelDispatcher cd = cdb as ChannelDispatcher; 

     if (cd != null) 
     { 
      cd.ErrorHandlers.Add(errorHandlerInstance); 
     } 
     } 
    } 

    public void Validate(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase) 
    { 
     foreach (var svcEndpoint in serviceDescription.Endpoints) 
     { 
     if (svcEndpoint.Contract.Name != "IMetadataExchange") 
     { 
      foreach (var opDesc in svcEndpoint.Contract.Operations) 
      { 
      if (opDesc.Faults.Count == 0) 
      { 
       string msg = string.Format(""); 
      } 
      } 
     } 
     } 
    } 
    } 

    public class TestErrorHandler : IErrorHandler 
    { 
    public bool HandleError(Exception error) 
    { 
     return true; 
    } 

    public void ProvideFault(Exception error, MessageVersion version, ref Message fault) 
    { 
     if (!(error is FaultException)) 
     { 
     ClsTestFaultContract exContract = new ClsTestFaultContract(); 

     FaultException<ClsTestFaultContract> fex = 
      new FaultException<ClsTestFaultContract>(exContract, exContract.DescricaoErro, 
      new FaultCode(Convert.ToString(exContract.CodigoErro))); 
     MessageFault msgFault = fex.CreateMessageFault(); 
     fault = Message.CreateMessage(version, msgFault, ErrorHandlerConstant.FaultAction); 
     } 
    } 
    } 
} 

내 인터페이스 중 하나입니다 :

다음
<?xml version="1.0"?> 
<configuration> 
    <system.web> 
    <compilation debug="true" targetFramework="4.0" /> 
    </system.web> 
    <system.serviceModel> 
    <extensions> 
     <behaviorExtensions> 
     <add name="ServiceErrorHandler" type="company.Test.appserver.implementation.ServiceErrorHandlerBehaviorExtensionElement, TestAppServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" /> 
     </behaviorExtensions> 
    </extensions> 
    <bindings> 
     <basicHttpBinding> 
     <binding name="SimpleBinding" /> 
     </basicHttpBinding> 
    </bindings> 
    <services> 
     <service behaviorConfiguration="DefaultBehavior" name="company.Test.appserver.implementation.TestUpdate"> 
     <endpoint address="udt" binding="basicHttpBinding" bindingConfiguration="SimpleBinding" 
      name="TestUpdate" bindingNamespace="http://company/Test/update/2011/04" 
      contract="company.Test.appserver.interfaces.ITestUpdate" /> 
     <endpoint address="mex" binding="mexHttpBinding" bindingConfiguration="" 
      name="TestUpdateMex" bindingNamespace="http://company/Test/update/2011/04" 
      contract="IMetadataExchange" /> 
     </service> 
     <service behaviorConfiguration="DefaultBehavior" name="company.Test.appserver.implementation.TestTransaction"> 
     <endpoint address="udt" binding="basicHttpBinding" bindingConfiguration="SimpleBinding" 
      name="TestTransacao" bindingNamespace="http://company/Test/transaction/2011/04" 
      contract="company.Test.appserver.interfaces.ITestTransacao" /> 
     <endpoint address="mex" binding="mexHttpBinding" bindingConfiguration="" 
      name="TestTransacaoMex" bindingNamespace="http://company/Test/transaction/2011/04" 
      contract="IMetadataExchange" /> 
     </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="DefaultBehavior"> 
      <serviceMetadata httpGetEnabled="true" httpGetBinding="webHttpBinding" 
      httpGetBindingConfiguration="" /> 
      <serviceDebug includeExceptionDetailInFaults="true" /> 
     </behavior> 
     <behavior name=""> 
      <serviceMetadata httpGetEnabled="true" httpGetBinding="webHttpBinding" 
      httpGetBindingConfiguration="" /> 
      <serviceDebug includeExceptionDetailInFaults="false" /> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> 
    </system.serviceModel> 
<system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"/> 
    </system.webServer> 
</configuration> 

내 오류 처리기에 대한 코드입니다 : 다음은 내 웹 설정입니다

namespace company.Test.appserver.interfaces 
{ 
    [ServiceContract(Namespace = "http://company/Test/transaction/2011/04", 
      Name = "ITestTransacao", SessionMode = SessionMode.Allowed)] 
    public interface ITestTransacao 
    { 
    [OperationContract] 
    [FaultContract(typeof(ClsTestFaultContract), Action = ErrorHandlerConstant.FaultAction)] 
    Int32 RegistrarTransacao(String Param1, String Param2, String Param3, Int32 Param4); 
    [OperationContract] 
    [FaultContract(typeof(ClsTestFaultContract), Action = ErrorHandlerConstant.FaultAction)] 
    void ConfirmarTransacao(String Param1, String Param2, Int32 Param3, String Param4, String Param5); 
    [OperationContract] 
    [FaultContract(typeof(ClsTestFaultContract), Action = ErrorHandlerConstant.FaultAction)] 
    void CancelarTransacao(String Param1, String Param2, String Param3, Int32 Param4, String Param5 = ""); 
    } 
} 

나는 많은 시간을 낭비했습니다, 그리고 나는 그 오류 처리를 깨뜨린 것이 무슨 일이 일어 났는지 알 수 없다. 그것은 훌륭하게 작동했다. 내가 가진 도움 후 나는 작업 코드 아래에 게시하도록하겠습니다 도움

편집

에 대한 TKS SO MUCH. TKS는 너무 많이 ... 다시 다음은 올바른 오류 핸들러 : 올바른 Web.config의 아래

namespace company.Test.appserver.implementation 
{ 
    public class ServiceErrorHandlerBehaviorExtensionElement : BehaviorExtensionElement 
    { 
    public override Type BehaviorType 
    { 
     get { return typeof(TestErrorHandler); } 
    } 

    protected override object CreateBehavior() 
    { 
     return new TestErrorHandler(); 
    } 
    } 

    public class TestErrorHandler : ServiceErrorHandlerBehaviorExtensionElement, IErrorHandler, IServiceBehavior 
    { 
    public bool HandleError(Exception error) 
    { 
     return true; 
    } 

    public void ProvideFault(Exception error, MessageVersion version, ref Message fault) 
    { 
     if (!(error is FaultException)) 
     { 
     ClsTestFaultContract exContract = new ClsTestFaultContract(); 

     FaultException<ClsTestFaultContract> fex = 
      new FaultException<ClsTestFaultContract>(exContract, exContract.DescricaoErro, 
      new FaultCode(Convert.ToString(exContract.CodigoErro))); 
     MessageFault msgFault = fex.CreateMessageFault(); 
     fault = Message.CreateMessage(version, msgFault, ErrorHandlerConstant.FaultAction); 
     } 
    } 

    public void AddBindingParameters(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase, Collection<ServiceEndpoint> endpoints, BindingParameterCollection bindingParameters) 
    { 

    } 

    public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase) 
    { 
     foreach (ChannelDispatcherBase cdb in serviceHostBase.ChannelDispatchers) 
     { 
     ChannelDispatcher cd = cdb as ChannelDispatcher; 

     if (cd != null) 
     { 
      cd.ErrorHandlers.Add(this); 
     } 
     } 
    } 

    public void Validate(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase) 
    { 
     foreach (var svcEndpoint in serviceDescription.Endpoints) 
     { 
     if (svcEndpoint.Contract.Name != "IMetadataExchange") 
     { 
      foreach (var opDesc in svcEndpoint.Contract.Operations) 
      { 
      if (opDesc.Faults.Count == 0) 
      { 
       string msg = string.Format(""); 
      } 
      } 
     } 
     } 
    } 
    } 
} 

하고

설정 파일은 ServiceErrorHandler 동작 확장 등록하지만, 그렇지 않아있다
<?xml version="1.0"?> 
<configuration> 
    <system.web> 
    <compilation debug="true" targetFramework="4.0" /> 
    </system.web> 
    <system.serviceModel> 
    <extensions> 
     <behaviorExtensions> 
     <add name="ServiceErrorHandler" type="company.Test.appserver.implementation.ServiceErrorHandlerBehaviorExtensionElement, TestAppServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" /> 
     </behaviorExtensions> 
    </extensions> 
    <bindings> 
     <basicHttpBinding> 
     <binding name="SimpleBinding" /> 
     </basicHttpBinding> 
    </bindings> 
    <services> 
     <service behaviorConfiguration="DefaultBehavior" name="company.Test.appserver.implementation.TestUpdate"> 
     <endpoint address="udt" binding="basicHttpBinding" bindingConfiguration="SimpleBinding" 
      name="TestUpdate" bindingNamespace="http://company/Test/update/2011/04" 
      contract="company.Test.appserver.interfaces.ITestUpdate" /> 
     <endpoint address="mex" binding="mexHttpBinding" bindingConfiguration="" 
      name="TestUpdateMex" bindingNamespace="http://company/Test/update/2011/04" 
      contract="IMetadataExchange" /> 
     </service> 
     <service behaviorConfiguration="DefaultBehavior" name="company.Test.appserver.implementation.TestTransaction"> 
     <endpoint address="udt" binding="basicHttpBinding" bindingConfiguration="SimpleBinding" 
      name="TestTransacao" bindingNamespace="http://company/Test/transaction/2011/04" 
      contract="company.Test.appserver.interfaces.ITestTransacao" /> 
     <endpoint address="mex" binding="mexHttpBinding" bindingConfiguration="" 
      name="TestTransacaoMex" bindingNamespace="http://company/Test/transaction/2011/04" 
      contract="IMetadataExchange" /> 
     </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="DefaultBehavior"> 
      <serviceMetadata httpGetEnabled="true" httpGetBinding="webHttpBinding" 
      httpGetBindingConfiguration="" /> 
      <serviceDebug includeExceptionDetailInFaults="true" /> 
      <ServiceErrorHandler /> 
     </behavior> 
     <behavior name=""> 
      <serviceMetadata httpGetEnabled="true" httpGetBinding="webHttpBinding" 
      httpGetBindingConfiguration="" /> 
      <serviceDebug includeExceptionDetailInFaults="false" /> 
      <ServiceErrorHandler /> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> 
    </system.serviceModel> 
<system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"/> 
    </system.webServer> 
</configuration> 

답변

4

실제로 < serviceBehaviors/> 아래의 컬렉션에서 사용하고 있습니다.

+0

그게 전부입니까? 없어진 물건 있어요? 두 번째 끝점을 구성 할 때 실수로 지워야합니다. Tks 너무 많이 – Pascal

+0

나는 그것을 얻었다. .. Tks 순전히. 그냥 실종 된 행동을 발견했습니다. 제 질문을 올바른 코드로 편집 할 것입니다. – Pascal

+0

질문을 편집 해 주셔서 감사합니다. 문제가 해결되었습니다. – NibblyPig

관련 문제