Note that there are some explanatory texts on larger screens.

plurals
  1. POMessageInspector message: "This message cannot support the operation because it has been copied."
    primarykey
    data
    text
    <p>Here's the thing: </p> <p>I have a business request that all WCF messages should have a specific header, for tracking and security reasons.</p> <p>Anyway, I setup an implementation of <code>MessageInspector</code> on both the client and the service -- we control both ends so far -- and all worked well on the prototype phase.</p> <p>However, today, something went awire and stopped working. </p> <p>I redid the prototype from scratch and things works just fine. I'm loosing my marbles over it for the entire afternoon.</p> <p>The relevant code is as follow:</p> <pre><code>public class DispatchEndpointBehavior : IEndpointBehavior { public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher) { var mi = new MessageInspector(); endpointDispatcher.DispatchRuntime.MessageInspectors.Add(mi); } // ... } public class DispatchMessageInspector : IDispatchMessageInspector { public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext) { var index = request.Headers.FindHeader("name", ""); if (index == -1) throw new MessageSecurityException("..."); var value = request.Headers.GetHeader&lt;Guid&gt;(index); // do something with the value return null; } // ... } public class ClientEndpointBehavior : IClientEndpointBehavior { public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime) { var mi = new ClientSecurityMessageInspector(); clientRuntime.MessageInspectors.Add(mi); } // ... } public class ClientSecurityMessageInspector : IClientMessageInspector { public object BeforeSendRequest(ref Message request, IClientChannel channel) { request.Headers.Add(MessageHeader.CreateHeader("name", "", Guid.NewGuid())); return null; } // ... } </code></pre> <p>Here is the configuration for the service:</p> <pre><code>&lt;system.serviceModel&gt; &lt;services&gt; &lt;service behaviorConfiguration="Default" name="[Service Name]"&gt; &lt;endpoint address="" binding="basicHttpBinding" behaviorConfiguration="headerBehavior" contract="[Service Contract]"/&gt; &lt;endpoint address="mex" ... /&gt; &lt;/service&gt; &lt;/services&gt; &lt;behaviors&gt; &lt;serviceBehaviors&gt; &lt;behavior name="Default"&gt; &lt;serviceMetadata httpGetEnabled="true" /&gt; &lt;serviceDebug includeExceptionDetailInFaults="true" /&gt; &lt;/behavior&gt; &lt;/serviceBehaviors&gt; &lt;endpointBehaviors&gt; &lt;behavior name="headerBehavior"&gt; &lt;headerBehavior headerName="token" /&gt; &lt;/behavior&gt; &lt;/endpointBehaviors&gt; &lt;/behaviors&gt; &lt;extensions&gt; &lt;behaviorExtensions&gt; &lt;add name="headerBehavior" type="[Implementation Type]" /&gt; &lt;/behaviorExtensions&gt; &lt;/extensions&gt; &lt;/system.serviceModel&gt; </code></pre> <p>Analogous, the client configuration is:</p> <pre><code>&lt;system.serviceModel&gt; &lt;bindings&gt; &lt;basicHttpBinding&gt; &lt;binding name="[Service name]" ... &gt; &lt;readerQuotas ... /&gt; &lt;security mode="None"&gt; &lt;transport clientCredentialType="None" proxyCredentialType="None" realm=""/&gt; &lt;message clientCredentialType="UserName" algorithmSuite="Default" /&gt; &lt;/security&gt; &lt;/binding&gt; &lt;/basicHttpBinding&gt; &lt;/bindings&gt; &lt;client&gt; &lt;endpoint address="http://.../MyService.svc" binding="basicHttpBinding" bindingConfiguration="Default" contract="[Service Contract]" name="[Service Name]" behaviorConfiguration="headerBehavior" /&gt; &lt;/client&gt; &lt;behaviors&gt; &lt;endpointBehaviors&gt; &lt;behavior name="headerBehavior"&gt; &lt;headerBehavior headerName="prosper-security-token" securityTokenValueService="[Implementation Type]" securityTokenValueGetterMethodName="[Method Name]" /&gt; &lt;/behavior&gt; &lt;/endpointBehaviors&gt; &lt;/behaviors&gt; &lt;extensions&gt; &lt;behaviorExtensions&gt; &lt;add name="headerBehavior" type="[Implementation Type]" /&gt; &lt;/behaviorExtensions&gt; &lt;/extensions&gt; &lt;/system.serviceModel&gt; </code></pre> <p><strong>Edited to Add</strong></p> <p>As requested, the exception stack trace is as follows:</p> <pre><code>(System.ServiceModel.FaultException) This message cannot support the operation because it has been copied. Server stack trace: at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc&amp; rpc) at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout) at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs) at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation) at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message) Exception rethrown at [0]: at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&amp; msgData, Int32 type) at ConsoleApplication1.UserManagementService.IUserManagement.CreateUser(String username, String password, String[] systemCodes) at ConsoleApplication1.UserManagementService.UserManagementClient.CreateUser(String username, String password, String[] systemCodes) in C:\Users\Paulo Santos\Documents\Visual Studio 2008\Projects\PJonDevelopment\ConsoleApplication1\ConsoleApplication1\Service References\UserManagementService\Reference.cs at ConsoleApplication1.Program.Main(String[] args) in C:\Users\Paulo Santos\Documents\Visual Studio 2008\Projects\PJonDevelopment\ConsoleApplication1\ConsoleApplication1\Program.cs </code></pre> <p><strong>Edited to Add</strong></p> <p>As told in one of the comments I've posted a prototype project that works here: <a href="http://pjondevelopment.50webs.com/files/ServiceModel.zip" rel="nofollow">ServiceModel.zip</a></p> <p>I can't stress enough that the prototype works. The only thing I don't know is why I suddenly started getting this weird message. I don't copy the message and only deal with headers, and everywhere I search say that reading the message is a big no-no.</p> <p>I dread the fact that with so many points to inspect, even replace, the entire message within <strong>WCF</strong> model, the architects designed with such an object that even if you look at it it goes poof.</p> <p>If you're giving the opportunity to inspect, make a solid objec that can sustain the hardships of behing manipulated by anyone who wants to inspect it.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload