Reputation: 23436
I have several WCF SOAP services that programmatically expose an endpoint to which an IEndPointBehavior
is attached.
var endpoint = AddServiceEndpoint(contractType,
basicBinding,
address);
_logger.Write("Adding behavior for service {0}, contract: {1}", serviceName, cd.Value.ContractType);
endpoint.Behaviors.Add(new MyBehavior());
In the behavior class, I add a message inspector to the Dispatch runtime:
void IEndpointBehavior.ApplyDispatchBehavior(ServiceEndpoint endpoint,
EndpointDispatcher endpointDispatcher)
{
_logger.WriteError("Adding Inspector to endpoint {0}, contract {1}", endpoint.Address.ToString(), endpoint.Contract.Name);
endpointDispatcher.DispatchRuntime.MessageInspectors.Add(new MyInspector());
}
In the message inspector, I implemented the AfterReceiveRequest
method like:
public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext)
{
_logger.WriteError("AfterReceiveRequest for {0} via {1}", request.Headers.Action, request.Properties.Via);
// implementation omitted...
return null;
}
Now I can see the 'Adding behavior' and 'Adding inspector' log messages for all my services, but the AfterReceiveRequest
method is only called for some services.
The services for which the method is not called are running under a different web application in IIS, but I cannot find anything different that would explain why this inspector would not work. The services in which the inspector is not working are also deriving from a different base class, but I ripped out all the code from that base class and still the method is not called.
I turned on message tracing and do see that the client is calling the correct endpoint.
Does anyone have an idea why this may happen or how I can better debug this?
Upvotes: 2
Views: 1744
Reputation: 57
But I made it work without implementing IInstanceContextProvider.. Just hookup your inspector object through contractbehavior instead of endpoint behavior.
Upvotes: 0
Reputation: 23436
I finally found the problem with my code. Both WCF services have a WIF (.NET 4.5) ClaimsAuthorizationManager
attached. The call to CheckAccess
was returning true
for one service and false
for the other. The one where it was returning false, never went on to call the AfterReceiveRequest
of the endpoint behavior.
I extended Carlos Figueira's incredibly useful commandline tool with a WIF ClaimsAuthenticationManager
and ClaimsAuthorizationManager
and found that their Authenticate
and CheckAccess
methods are called before the AfterReceiveRequest
on the DispatchMessageInspector
.
As I needed an extension point that was called before the CheckAccess, I ended up using a class implementing IInstanceContextProvider
Upvotes: 2