ServiceDebugBehavior.IncludeExceptionDetailInFaults Propriedade
Definição
Um valor que especifica se são incluídas informações de exceção gerenciada no detalhe de falhas SOAP retornadas para o cliente para fins de depuração.Gets or sets a value that specifies whether to include managed exception information in the detail of SOAP faults returned to the client for debugging purposes.
public:
property bool IncludeExceptionDetailInFaults { bool get(); void set(bool value); };
public bool IncludeExceptionDetailInFaults { get; set; }
member this.IncludeExceptionDetailInFaults : bool with get, set
Public Property IncludeExceptionDetailInFaults As Boolean
Valor da propriedade
true se Windows Communication Foundation (WCF) retornar informações de exceção gerenciada nas falhas de SOAP para fins de depuração de cliente; caso contrário, false .true if Windows Communication Foundation (WCF) returns managed exception information in the SOAP faults for client debugging purposes; otherwise, false. O padrão é false.The default is false.
Exemplos
O exemplo de código a seguir mostra como usar um arquivo de configuração para habilitar o recurso de página de ajuda HTML e retornar informações de exceção dentro de uma falha de SOAP para o cliente para fins de depuração.The following code example shows how to use a configuration file to enable the HTML help page feature and return exception information inside a SOAP fault back to the client for debugging purposes. Este arquivo de configuração mostra as seguintes etapas básicas para adicionar suporte para os ServiceDebugBehavior recursos do:This configuration file shows the following basic steps to adding support for the ServiceDebugBehavior features:
Como o ServiceDebugBehavior tipo é uma System.ServiceModel.Description.IServiceBehavior implementação, o elemento < Service > que representa o tipo de serviço tem um identificador de configuração de comportamento de
behaviorConfiguration="metadataAndDebug".Because the ServiceDebugBehavior type is an System.ServiceModel.Description.IServiceBehavior implementation, the <service> element that represents the service type has a behavior configuration identifier ofbehaviorConfiguration="metadataAndDebug".Novamente, como o ServiceDebugBehavior tipo é uma System.ServiceModel.Description.IServiceBehavior implementação, um elemento de < comportamento > é adicionado < > a uma seção de percomportamentos.Again, because the ServiceDebugBehavior type is an System.ServiceModel.Description.IServiceBehavior implementation a <behavior> element is added to a <serviceBehaviors> section. Defina o
nameatributo do elemento de < > comportamento como o valor que é o identificador dobehaviorConfigurationatributo do elemento de < serviço > .Set thenameattribute of the <behavior> element the value of which is the identifier of thebehaviorConfigurationattribute of the <service> element. Nesse caso, o valor émetadataAndDebug.In this case, the value ismetadataAndDebug.Adicione um elemento de < userdebug > com os vários atributos definidos para a configuração desejada.Add a <serviceDebug> element with the various attributes set to the desired configuration. Nesse caso, os
httpHelpPageEnabledvalores deincludeExceptionDetailInFaultsatributo e são definidos comotrue.In this case, thehttpHelpPageEnabledandincludeExceptionDetailInFaultsattribute values are set totrue.
<configuration>
<system.serviceModel>
<services>
<!--
Step 1. Add a behaviorConfiguration attribute
in the <service> element.
-->
<service
name="Microsoft.WCF.Documentation.SampleService"
behaviorConfiguration="metadataAndDebug">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/SampleService" />
</baseAddresses>
</host>
<endpoint
address=""
binding="wsHttpBinding"
contract="Microsoft.WCF.Documentation.ISampleService"
/>
<endpoint
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange"
/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<!--
Step 2. Inside a <serviceBehaviors> section, add
a name attribute in the <behaviors> element that
matches the behaviorConfiguration attribute in the
<service> element above.
-->
<behavior name="metadataAndDebug">
<serviceMetadata
httpGetEnabled="true"
httpGetUrl=""
/>
<!--
Step 3. Add a <serviceDebug> element and
modify the various attributes that suit your
scenario.
-->
<serviceDebug
httpHelpPageEnabled="true"
includeExceptionDetailInFaults="true"
/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
Comentários
Defina a IncludeExceptionDetailInFaults propriedade como true para instruir o WCF a retornar informações de exceção gerenciada ao cliente em falhas de SOAP para facilitar a depuração.Set the IncludeExceptionDetailInFaults property to true to instruct WCF to return managed exception information to the client in SOAP faults to ease debugging.
Cuidado
Retornar informações de exceção gerenciada aos clientes pode ser um risco de segurança, pois os detalhes da exceção expõem informações sobre a implementação do serviço interno que poderia ser usada por clientes não autorizados.Returning managed exception information to clients can be a security risk because exception details expose information about the internal service implementation that could be used by unauthorized clients. Além disso, embora as ServiceDebugBehavior Propriedades também possam ser definidas programaticamente, pode ser fácil esquecer de desabilitar IncludeExceptionDetailInFaults ao implantar o.In addition, although the ServiceDebugBehavior properties can also be set programmatically, it can be easy to forget to disable IncludeExceptionDetailInFaults when deploying.
Devido aos problemas de segurança envolvidos, é altamente recomendável que:Because of the security issues involved, it is strongly recommended that:
Você usa um arquivo de configuração de aplicativo para definir o valor da IncludeExceptionDetailInFaults propriedade como
true.You use an application configuration file to set the value of the IncludeExceptionDetailInFaults property totrue.Você só faz isso em cenários de depuração controlados.You only do so only in controlled debugging scenarios.
Para obter mais informações, consulte especificando e manipulando falhas em contratos e serviços.For more information, see Specifying and Handling Faults in Contracts and Services.