Search code examples
wcfvisual-studio-2010idispatchmessageinspector

VS2010 "Update Service Reference" to WCF where behavior extensions inspect and change messages


I'm using an encrypted timestamp to secure communications between a WCF service in my web server and another in the 'mid-tier'. In the calling service (the client in this exchange) I'm using a DLL whose class inherits System.ServiceModel.Configuration.BehaviorExtensionElement to provide functionality implementing System.ServiceModel.Description.IEndpointBehavior and System.ServiceModel.Dispatcher.IClientMessageInspector. This is glued in via the web.config file with the sections

<extensions>
 <behaviorExtensions>
  <add name="MessageInspectorBehavior" type="MessageInspectorDLL.MessageInspectorBehaviorExtensionElement, MessageInspectorDLL, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
 </behaviorExtensions>
</extensions>

<endpointBehaviors>
  <behavior name="MessageInspectorEndpointBehavior">
    <MessageInspectorBehavior />
  </behavior>
</endpointBehaviors>

and then these are hooked up to the mid-tier WCF with entries like this one

<client>
  <endpoint address="http://blah.cloudapp.net:8080/BlahService.svc"
    behaviorConfiguration="MessageInspectorEndpointBehavior" binding="customBinding"
    bindingConfiguration="CustomBinding_BlahService"
    contract="BlahServiceReference.BlahService"
    name="CustomBinding_BlahService" />

In the mid-tier there's a similar story with a System.ServiceModel.Dispatcher.IClientMessageInspector decrypting the time stamp and either processing the request or throwing a System.ServiceModel.FaultException with the error message "Invalid stamp".

This follows code examples at http://msdn.microsoft.com/en-us/library/ms733747.aspx and http://weblogs.asp.net/paolopia/archive/2007/08/23/writing-a-wcf-message-inspector.aspx

Now I have changed the mid-tier WCF. Some changes are simple (e.g. correcting a spelling mistake in a method name "retrive" -> "retrieve") while some adds more substantial functionality and I want to update the service recerences in the client. In VS2010 I right-click on the service references that will need updating and select "Update Service Reference". VS2010 connects to the mid-tier WCF ("downloading service information") and then throws the error

The configuration for the service reference could not be updated due to the following issue: The type 'MessageInspectorDLL.MessageInspectorExtensionElement, MessageInspectorDLL, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' registered for extension 'MessageInspectorBehavior' could not be loaded. (C:\TFS\Blah\Blah\web.config line 80)

What's wrong? Is there something I need to set up for the update service reference to correctly use the message inspector DLL?

Though it is possible that the DLL or the web.config have errors that seems unlikely since the client will connect to the previous mid-tier which is up on Azure, and that has the same encrypted timestamp inspection.


Solution

  • I've found an answer. Adding the MessageInspectorDLL as a reference to the ASP application fixed it for me.