Computers, Programming, Technology, Music, Literature

Archive for the ‘WCF’ Category

Enable WCF help page and exception details in FaultException

leave a comment »

 

 

via config file

<configuration>
	<system.serviceModel>
		<services>
			<service name="HWService" behaviorConfiguration="metadataAndDebug">
				<host>
					<baseAddresses>
						<add baseAddress="http://localhost:8080/HWService" />
					</baseAddresses>  
				</host>
				<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
			</service>
		</services>	
		<behaviors>
			<serviceBehaviors>
				<behavior name="metadataAndDebug">
					<serviceMetadata  httpGetEnabled="true" httpGetUrl=""/>
					<serviceDebug httpHelpPageEnabled="true" includeExceptionDetailInFaults="true" />
				</behavior>
			</serviceBehaviors>
		</behaviors>
	</system.serviceModel>
</configuration>

via code

ServiceHost host = new ServiceHost(typeof(HWService));

ServiceDebugBehavior debug = host.Description.Behaviors.Find<ServiceDebugBehavior>();

// if not found,  turn the setting on with a behavior
if (debug == null)
{
    host.Description.Behaviors.Add(
         new ServiceDebugBehavior() { IncludeExceptionDetailInFaults = true });
}
else
{  
    // make sure setting is on
    if (!debug.IncludeExceptionDetailInFaults)
    {
        debug.IncludeExceptionDetailInFaults = true;
    }
}

host.Open();

 

via code (with attribute)

 

[ServiceBehaviour(IncludeExceptionDetailInFaults=true)]
public class HWService : IHWService
{
	//code 😉
}
Advertisements

Written by gmaran23

March 20, 2013 at 9:39 am

Posted in .Net, C#, WCF

Tagged with , ,