WCF Server side logging message send back progress - wcf

I am getting timeouts on the client side and I am not sure if the issue is the package size or the network.
On the server side is there a way of logging the progress of the message being sent to the client?
Or at least the size of the package being sent on the transport layer?
Note: I've looked into WCF Logging options before posting question, but couldn't find anything regarding the message size, especially if binding is not Http so there is no specific header with the Content-Length.
Thanks

You can add to your config file these lines:
<system.diagnostics>
<sources>
<source name="System.ServiceModel" switchValue="Verbose,ActivityTracing">
<listeners>
<add name="ServiceModelTraceListener" initializeData="c:\MyTracelog.svclog" type="System.Diagnostics.XmlWriterTraceListener, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" traceOutputOptions="Timestamp"/>
</listeners>
</source>
</sources>
<trace autoflush="true" />
</system.diagnostics>
<system.serviceModel>
<diagnostics>
<messageLogging logEntireMessage="true" logMalformedMessages="true" logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true" />
</diagnostics>
</system.serviceModel>
More information you can find on MSDN page.

This was the best thing I did manage to achieve, couldn't find anything out of the box:
public class MessageSizeBehaviorAttribute : Attribute, IContractBehavior
{
public void Validate(ContractDescription contractDescription, ServiceEndpoint endpoint)
{
}
public void ApplyDispatchBehavior(ContractDescription contractDescription, ServiceEndpoint endpoint, DispatchRuntime dispatchRuntime)
{
dispatchRuntime.MessageInspectors.Add(new MessageSizeInspector());
}
public void ApplyClientBehavior(ContractDescription contractDescription, ServiceEndpoint endpoint, ClientRuntime clientRuntime)
{
}
public void AddBindingParameters(ContractDescription contractDescription, ServiceEndpoint endpoint,
BindingParameterCollection bindingParameters)
{
}
}
public class MessageSizeInspector : IDispatchMessageInspector
{
public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext)
{
return request;
}
public void BeforeSendReply(ref Message reply, object correlationState)
{
try
{
if (reply.IsFault || reply.IsEmpty) return;
var buffer = reply.CreateBufferedCopy(int.MaxValue);
reply = buffer.CreateMessage();
var messageBodyReader = buffer.CreateMessage().GetReaderAtBodyContents();
var messageBody = messageBodyReader.ReadOuterXml();
LogMessageSize(messageBody);
}
catch (Exception e)
{
Debug.WriteLine(e);
}
}
private void LogMessageSize(string messageBody)
{
double messageSize = Encoding.UTF8.GetByteCount(messageBody);
Debug.WriteLine("Message size in MBytes {0}", messageSize / 1024 / 1024);
}
}

Related

Unable to Catch the FaultException thrown by WCF Service in SilverLight client Application

I am Calling a WCF Service Method from my Silverlight Application. Wcf Service is returning a Fault Exception on Failure. I am able to throw the fault exception from my WCF Service. But it is not receiving to my Silverlight Application(.xaml.cs). Instead I am getting an exception "Communication Exception was unhandled by User, the remote server returned an Error:NotFound"
in References.cs file(AutoGenerated File)
I am calling the WCF Service Method in my .Xaml.cs file like below
private void btnExecuteQuery_Click(object sender, RoutedEventArgs e)
{
try
{
objService.GetDataTableDataAsync(_DATABASENAME, strQuery);
objService.GetDataTableDataCompleted += new EventHandler<GetDataTableDataCompletedEventArgs>(objService_GetDataTableDataCompleted);
}
catch (FaultException<MyFaultException> ex)
{
lblErrorMessage.Content = "Please Enter a Valid SQL Query";
}
}
And I wrote my GetDataTableDataCompleted event as below
void objService_GetDataTableDataCompleted(object sender, GetDataTableDataCompletedEventArgse)
{
//code
}
Here is my Service Method
public IEnumerable<Dictionary<string, object>> GetDataTableData(string dataBaseName, string query)
{
try
{
IEnumerable<Dictionary<string, object>> objDictionary;
objDictionary = objOptimityDAL.GetDataForSelectQuery(dataBaseName, query);
return objDictionary;
}
catch (Exception ex)
{
MyFaultException fault = new MyFaultException();
fault.Reason = ex.Message.ToString();
throw new FaultException<MyFaultException>(fault, new FaultReason("Incorrect SQL Query"));
}
}
Here My WCf Service is interacting with Data Access Layer and throwing the Fault Exception Successfully but it is not receiving to my client Method, Instead I am getting an unhandled Exception like
"Communication Exception was unhandled by User, the remote server returned an Error:NotFound" in References.cs code shown below
public System.Collections.ObjectModel.ObservableCollection<System.Collections.Generic.Dictionary<string, object>> EndGetDataTableData(System.IAsyncResult result) {
object[] _args = new object[0];
System.Collections.ObjectModel.ObservableCollection<System.Collections.Generic.Dictionary<string, object>> _result = ((System.Collections.ObjectModel.ObservableCollection<System.Collections.Generic.Dictionary<string, object>>)(base.EndInvoke("GetDataTableData", _args, result)));
return _result;
}
Here is the Web.config of Wcf Service
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
Below is my ServiceReferences.ClientConfig file
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService1"
maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647"
closeTimeout="01:00:00"
receiveTimeout="01:00:00"
sendTimeout="01:00:00">
<security mode="None" />
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:3132/Service1.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IService1" contract="ServiceReference1.IService1"
name="BasicHttpBinding_IService1" />
</client>
</system.serviceModel>
</configuration>
Please Suggest me someway to catch the faultException in my SilverlightClient
Thanks in Advance
You should have chosen Silverlight Enabled WCF Service when you created your service first time. It would have created all the infrastructure for you.
But you can still add the necessary code manually to the WCF Service project.
SilverlightFaultBehavior.cs
/// <summary>
/// The behavior which enables FaultExceptions for Silverlight clients
/// </summary>
[AttributeUsage(AttributeTargets.Class)]
public sealed class SilverlightFaultBehaviorAttribute : Attribute, IServiceBehavior
{
private class SilverlightFaultEndpointBehavior : IEndpointBehavior
{
public void AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection bindingParameters)
{
}
public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)
{
}
public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
{
endpointDispatcher.DispatchRuntime.MessageInspectors.Add(new SilverlightFaultMessageInspector());
}
public void Validate(ServiceEndpoint endpoint)
{
}
private class SilverlightFaultMessageInspector : IDispatchMessageInspector
{
public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext)
{
return null;
}
public void BeforeSendReply(ref Message reply, object correlationState)
{
if ((reply != null) && reply.IsFault)
{
HttpResponseMessageProperty property = new HttpResponseMessageProperty();
property.StatusCode = HttpStatusCode.OK;
reply.Properties[HttpResponseMessageProperty.Name] = property;
}
}
}
}
public void AddBindingParameters(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase, Collection<ServiceEndpoint> endpoints, BindingParameterCollection bindingParameters)
{
}
public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
{
foreach (ServiceEndpoint endpoint in serviceDescription.Endpoints)
{
endpoint.Behaviors.Add(new SilverlightFaultEndpointBehavior());
}
}
public void Validate(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
{
}
}
Service1.cs
[SilverlightFaultBehaviorAttribute]
public class Service1 : IService1
{
...
}
And on the client you should check the e.Error property inside the callback function. Try/catch from your example will not work.
The Silverlight Client
objService.GetDataTableDataCompleted += (s, e) =>
{
if(e.Error != null) {
if (e.Error is FaultException) {
lblErrorMessage.Content = "Please Enter a Valid SQL Query";
}
// do something with other errors
}
else {
// success
}
};
objService.GetDataTableDataAsync(_DATABASEName, strQuery);

Unable to make IDispatchMessageInspector work

I need to play with request header in a REST, Json, WCF web service.
I create my IDispatchMessageInspector
public class HeaderInspector : IDispatchMessageInspector
{
public object AfterReceiveRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel, System.ServiceModel.InstanceContext instanceContext)
{
int ind = request.Headers.FindHeader("xxxxx", "");
return null;
}
public void BeforeSendReply(ref System.ServiceModel.Channels.Message reply, object correlationState)
{
}
}
Then a endpointbehavio to attach the inspector to endpoints :
public class HeaderInspectorBehavior : IEndpointBehavior
{
public void AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection bindingParameters)
{
}
public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)
{
}
public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
{
HeaderInspector headerinsp = new HeaderInspector();
endpointDispatcher.DispatchRuntime.MessageInspectors.Add(new HeaderInspector());
}
public void Validate(ServiceEndpoint endpoint)
{
}
}
And finally a BehaviorExtensionElement :
public class MyExtension : BehaviorExtensionElement
{
public override Type BehaviorType
{
get { return typeof(HeaderInspectorBehavior); }
}
protected override object CreateBehavior()
{
return new HeaderInspectorBehavior();
}
}
Those classes being in the same file / namespace PDM.WebService
My config is :
<behaviors>
<endpointBehaviors>
<behavior name="RestBehavior">
<HeaderInspectorBehavior/>
<webHttp helpEnabled="true" defaultOutgoingResponseFormat="Json" faultExceptionEnabled="true" automaticFormatSelectionEnabled="false" />
</behavior>
</endpointBehaviors>
</behaviors>
<extensions>
<behaviorExtensions>
<add name="HeaderInspectorBehavior" type="PDM.WebService.MyExtension, PDM.WebService, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
</behaviorExtensions>
</extensions>
Everything compile well, at execution i can catch the execution of method "public override Type BehaviorType",
but no other methods of the code are fired after that (i sent request and i got response, the service respond well).
i set debug point in every methods nothing else execute ! (especially ApplyDispatchBehavior).
Can somebody point out what i'm missing ?
Refer CreateBehavior() is not invoked for a similar issue.
Ensure that name of your service element is corresponding to mynamespace.myservicename
The service will be providing correct response even if you don't have the correct service name; but the CreateBehavior() will be called only when you have the correct name for the service element.
Example
<service
name="WcfServiceApp001.Service1"
behaviorConfiguration="InternalPayrollBehavior">
<endpoint address="" binding="basicHttpBinding"
behaviorConfiguration="EndpointBehavior"
contract="WcfServiceApp001.IService1"
/>
</service>

How can I change the WCF Router Backup List Behavior with Custom Filter?

I'm trying to find a way to handle exception in WCF router, it means when for any reason router can not send message to primary endpoint (here, there is EndpointNotFoundException, ServerTooBusyException, or CommunicationObjectFaultedException) and goes and select an endpoint from backup list and send this message to backup endpoint. how can I get this internal exception in router service? because at this time I want to change the router configuration dynamically in memory and change the backup endpoint with primary endpoint. is it possible to do this with IErrorHandler? or is it possible to do this Custom Filter ? How I can change the backup behavior with Custom Filter?
this is a full working example to implement IErrorHandler fo wcf service. we can implement this for WCF Router and get the internal exception in router level and then make decision how we can change the configuration in the runtime.
[ServiceContract]
public interface IService1
{
[OperationContract]
[FaultContract(typeof(MyFault))]
string GetData(int value);
}
[DataContract]
public class MyFault
{
}
public class Service1 : IService1
{
public string GetData(int value)
{
throw new Exception("error");
}
}
public class MyErrorHandler : IErrorHandler
{
public bool HandleError(Exception error)
{
return true;
}
public void ProvideFault(Exception error, MessageVersion version, ref Message msg)
{
var vfc = new MyFault();
var fe = new FaultException<MyFault>(vfc);
var fault = fe.CreateMessageFault();
msg = Message.CreateMessage(version, fault, "http://ns");
}
}
public class ErrorHandlerExtension : BehaviorExtensionElement, IServiceBehavior
{
public override Type BehaviorType
{
get { return GetType(); }
}
protected override object CreateBehavior()
{
return this;
}
private IErrorHandler GetInstance()
{
return new MyErrorHandler();
}
void IServiceBehavior.AddBindingParameters(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase, Collection<ServiceEndpoint> endpoints, BindingParameterCollection bindingParameters)
{
}
void IServiceBehavior.ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
{
IErrorHandler errorHandlerInstance = GetInstance();
foreach (ChannelDispatcher dispatcher in serviceHostBase.ChannelDispatchers)
{
dispatcher.ErrorHandlers.Add(errorHandlerInstance);
}
}
void IServiceBehavior.Validate(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
{
foreach (ServiceEndpoint endpoint in serviceDescription.Endpoints)
{
if (endpoint.Contract.Name.Equals("IMetadataExchange") && endpoint.Contract.Namespace.Equals("http://schemas.microsoft.com/2006/04/mex"))
continue;
foreach (OperationDescription description in endpoint.Contract.Operations)
{
if (description.Faults.Count == 0)
{
throw new InvalidOperationException("FaultContractAttribute not found on this method");
}
}
}
}
}
web.config:
<system.serviceModel>
<services>
<service name="ToDD.Service1">
<endpoint address="" binding="basicHttpBinding" contract="ToDD.IService1" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
<errorHandler />
</behavior>
</serviceBehaviors>
</behaviors>
<extensions>
<behaviorExtensions>
<add name="errorHandler" type="ToDD.ErrorHandlerExtension, ToDD, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
</behaviorExtensions>
</extensions>
</system.serviceModel>
so in HandleError method we can handle this exception in proper way.

How to stop self-hosted WCF service upon unhandled errors?

I have a self-hosted WCF service that is running as a Windows Service. For the tests, I'm running it as a console application.
I'd like to catch all unhandled exceptions that happen in the service and shutdown the host. I'd like to catch all non FaultExceptions that happen when producing a response, but also all exceptions that are thrown in "idle mode" - i.e. thrown from some worker threads.
Unfortunatelly, I can't handle the exceptions neither by IErrorHandler (not called), nor by AppDomain.CurrentDomain.UnhandledException (not raised).
Any clues?
App.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="TestServiceBahavior">
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="TestServiceBahavior" name="WcfErrorHandling.TestService">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8001/TestService" />
</baseAddresses>
</host>
<endpoint address="" binding="basicHttpBinding"
bindingConfiguration="" contract="WcfErrorHandling.ITestService" />
<endpoint address="mex" binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
</configuration>
The code:
using System;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Dispatcher;
namespace WcfErrorHandling
{
[ServiceContract]
interface ITestService
{
[OperationContract]
string SayHello(string param);
}
public class TestService : ITestService
{
public string SayHello(string param)
{
if (param == "ae")
throw new ArgumentException("argument exception");
if (param == "fe")
throw new FaultException("fault exception");
return "hello";
}
}
public class TestHost : ServiceHost, IErrorHandler
{
public TestHost()
: base(typeof(TestService))
{
}
public void Start()
{
AppDomain.CurrentDomain.UnhandledException +=
(sender, ea) => UnhandledExceptionHandler(ea.ExceptionObject as Exception);
Open();
foreach (var channelDispatcher in ChannelDispatchers.OfType<ChannelDispatcher>())
channelDispatcher.ErrorHandlers.Add(this);
}
public void ProvideFault(Exception error, MessageVersion version, ref Message fault)
{
// do nothing
}
public bool HandleError(Exception error)
{
if (!(error is FaultException))
UnhandledExceptionHandler(error);
return true;
}
private void UnhandledExceptionHandler(Exception ex)
{
Close();
Environment.Exit(1);
}
}
public class Program
{
public static void Main(string[] args)
{
var testHost = new TestHost();
testHost.Start();
Console.Out.WriteLine("Press any key to exit...");
Console.ReadKey();
testHost.Close();
}
}
}
Had the same problem, this solved it for me:
Make your service implement this interface:
public class MyService : System.ServiceModel.Description.IServiceBehavior
Implement it like this:
public void AddBindingParameters(System.ServiceModel.Description.ServiceDescription serviceDescription, ServiceHostBase serviceHostBase, System.Collections.ObjectModel.Collection<System.ServiceModel.Description.ServiceEndpoint> endpoints, System.ServiceModel.Channels.BindingParameterCollection bindingParameters)
{
return;
}
public void ApplyDispatchBehavior(System.ServiceModel.Description.ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
{
foreach (ChannelDispatcher channel in serviceHostBase.ChannelDispatchers) { channel.ErrorHandlers.Add(new ErrorHandler()); }
}
public void Validate(System.ServiceModel.Description.ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
{
return;
}
And add this class:
public class ErrorHandler : IErrorHandler
{
bool IErrorHandler.HandleError(Exception error)
{ return true; }
void IErrorHandler.ProvideFault(Exception error, System.ServiceModel.Channels.MessageVersion version, ref System.ServiceModel.Channels.Message fault)
{ return; }
}
Now set a breakpoint on HandleError.. it will show you the exception

IErrorHandler doesn't seem to be handling my errors in WCF .. any ideas?

Have been reading around on IErrorHandler and want to go the config route.
so, I have read the following in an attempt to implement it.
MSDN
Keyvan Nayyeri blog about the type defintion
Rory Primrose Blog
This is basically just the msdn example wrapped in a class that inherits IErrorHandler and IServiceBehaviour ... then this is wrapped in the Extension element that inherits from BehaviourExtensionElement to allegedly allow me to add the element into the web.config. What have i missed?
I have got it to compile and from the various errors i have fixed it seems like WCF is actually loading the error handler. My problem is that the exception that i am throwing to handle in the error handler doesn;t get the exception passed to it.
My service implementation simply calls a method on another class that throws ArgumentOutOfRangeException - however this exception never gets handled by the handler.
My web.config
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="basic">
<security mode="None" />
</binding>
</basicHttpBinding>
</bindings>
<extensions>
<behaviorExtensions>
<add name="customHttpBehavior"
type="ErrorHandlerTest.ErrorHandlerElement, ErrorHandlerTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
</behaviorExtensions>
</extensions>
<behaviors>
<serviceBehaviors>
<behavior name="exceptionHandlerBehaviour">
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true"/>
<customHttpBehavior />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="exceptionHandlerBehaviour" name="ErrorHandlerTest.Service1">
<endpoint binding="basicHttpBinding" bindingConfiguration="basic" contract="ErrorHandlerTest.IService1" />
</service>
</services>
Service Contract
[ServiceContract]
public interface IService1
{
[OperationContract]
[FaultContract(typeof(GeneralInternalFault))]
string GetData(int value);
}
The ErrorHandler class
public class ErrorHandler : IErrorHandler , IServiceBehavior
{
public bool HandleError(Exception error)
{
Console.WriteLine("caught exception {0}:",error.Message );
return true;
}
public void ProvideFault(Exception error, MessageVersion version, ref Message fault)
{
if (fault!=null )
{
if (error is ArgumentOutOfRangeException )
{
var fe = new FaultException<GeneralInternalFault>(new GeneralInternalFault("general internal fault."));
MessageFault mf = fe.CreateMessageFault();
fault = Message.CreateMessage(version, mf, fe.Action);
}
else
{
var fe = new FaultException<GeneralInternalFault>(new GeneralInternalFault(" the other general internal fault."));
MessageFault mf = fe.CreateMessageFault();
fault = Message.CreateMessage(version, mf, fe.Action);
}
}
}
public void AddBindingParameters(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase, System.Collections.ObjectModel.Collection<ServiceEndpoint> endpoints, BindingParameterCollection bindingParameters)
{
}
public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
{
IErrorHandler errorHandler = new ErrorHandler();
foreach (ChannelDispatcherBase channelDispatcherBase in serviceHostBase.ChannelDispatchers)
{
ChannelDispatcher channelDispatcher = channelDispatcherBase as ChannelDispatcher;
if (channelDispatcher != null)
{
channelDispatcher.ErrorHandlers.Add(errorHandler);
}
}
}
public void Validate(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
{
}
}
And the Behaviour Extension Element
public class ErrorHandlerElement : BehaviorExtensionElement
{
protected override object CreateBehavior()
{
return new ErrorHandler();
}
public override Type BehaviorType
{
get { return typeof(ErrorHandler); }
}
}
Here's a full working example:
[ServiceContract]
public interface IService1
{
[OperationContract]
[FaultContract(typeof(MyFault))]
string GetData(int value);
}
[DataContract]
public class MyFault
{
}
public class Service1 : IService1
{
public string GetData(int value)
{
throw new Exception("error");
}
}
public class MyErrorHandler : IErrorHandler
{
public bool HandleError(Exception error)
{
return true;
}
public void ProvideFault(Exception error, MessageVersion version, ref Message msg)
{
var vfc = new MyFault();
var fe = new FaultException<MyFault>(vfc);
var fault = fe.CreateMessageFault();
msg = Message.CreateMessage(version, fault, "http://ns");
}
}
public class ErrorHandlerExtension : BehaviorExtensionElement, IServiceBehavior
{
public override Type BehaviorType
{
get { return GetType(); }
}
protected override object CreateBehavior()
{
return this;
}
private IErrorHandler GetInstance()
{
return new MyErrorHandler();
}
void IServiceBehavior.AddBindingParameters(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase, Collection<ServiceEndpoint> endpoints, BindingParameterCollection bindingParameters)
{
}
void IServiceBehavior.ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
{
IErrorHandler errorHandlerInstance = GetInstance();
foreach (ChannelDispatcher dispatcher in serviceHostBase.ChannelDispatchers)
{
dispatcher.ErrorHandlers.Add(errorHandlerInstance);
}
}
void IServiceBehavior.Validate(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
{
foreach (ServiceEndpoint endpoint in serviceDescription.Endpoints)
{
if (endpoint.Contract.Name.Equals("IMetadataExchange") &&
endpoint.Contract.Namespace.Equals("http://schemas.microsoft.com/2006/04/mex"))
continue;
foreach (OperationDescription description in endpoint.Contract.Operations)
{
if (description.Faults.Count == 0)
{
throw new InvalidOperationException("FaultContractAttribute not found on this method");
}
}
}
}
}
and web.config:
<system.serviceModel>
<services>
<service name="ToDD.Service1">
<endpoint address=""
binding="basicHttpBinding"
contract="ToDD.IService1" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
<errorHandler />
</behavior>
</serviceBehaviors>
</behaviors>
<extensions>
<behaviorExtensions>
<add name="errorHandler"
type="ToDD.ErrorHandlerExtension, ToDD, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
</behaviorExtensions>
</extensions>
</system.serviceModel>
You can see if the web.config is working and loading by adding a print or a breakpoint to the ApplyDispatchBehavior, and see if that gets printed/hit when the service first opens. So is it being loaded?
I'd add a print/breakpoint at ProvideFault, as well.