I am working on a custom WCF EndpoingBehavior that will modify the
messages coming in and out of my Service. I am having an error
related to the modification of the message in the
IEndpointBehavior.AfterReceiveRequest(ref Message request,...) method.
In the method that creates a new message, I have something similar
to ...
/// xmlReader defined with new modified content....
/// 'message' is the original message...
Message newMsg = Message.CreateMessage( message.Version,
null, xmlReader );
// Preserve the headers of the original message
newMsg.Headers.CopyHeadersFrom( message );
foreach (string propertyKey in message.Properties.Keys)
newMsg.Properties.Add(propertyKey, message.Properties[propertyKey]);
// Close the original message and return new message
message.Close( );
return newMsg;
This is similar to other code that I have seen on the Internet related
to creating a new message from an existing one. This code ran fine
when under the XP ASP.NET Development server, but when run on Windows
2003 Server (basicHttpBinding, HTTPS, Authentication) I immediately
get an error on the server side after the AfterReceiveRequest method
completes and processing the message. I get the following error...
System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'System.ServiceModel.Security.SecurityMessagePrope rty'.
at
System.ServiceModel.Security.SecurityMessageProper ty.ThrowIfDisposed()
at
System.ServiceModel.Security.SecurityMessageProper ty.get_ServiceSecurityContext()
at
System.ServiceModel.Dispatcher.SecurityImpersonati onBehavior.GetAndCacheSecurityContext(MessageRpc&
rpc)
at
System.ServiceModel.Dispatcher.SecurityImpersonati onBehavior.StartImpersonation(MessageRpc&
rpc, IDisposable& impersonationContext, IPrincipal&
originalPrincipal)
at
System.ServiceModel.Dispatcher.DispatchOperationRu ntime.InvokeBegin(MessageRpc&
rpc)
at
System.ServiceModel.Dispatcher.ImmutableDispatchRu ntime.ProcessMessage5(MessageRpc&
rpc)
at
System.ServiceModel.Dispatcher.ImmutableDispatchRu ntime.ProcessMessage4(MessageRpc&
rpc)
at
System.ServiceModel.Dispatcher.ImmutableDispatchRu ntime.ProcessMessage3(MessageRpc&
rpc)
at
System.ServiceModel.Dispatcher.ImmutableDispatchRu ntime.ProcessMessage2(MessageRpc&
rpc)
at
System.ServiceModel.Dispatcher.ImmutableDispatchRu ntime.ProcessMessage1(MessageRpc&
rpc)
at System.ServiceModel.Dispatcher.MessageRpc.Process( Boolean
isOperationContextSet)
I see where there was a similar bug in .NET before it was officially
release and supposedly fixed,
http://connect.microsoft.com/wcf/fee...dbackID=202762
Apparently, something in the new message or in the processing still
keeps a reference to the original Message and throws an error if it is
closed. If I remove the message.Close() then things work ok.
Any ideas on how to properly create a new Message?
What is the downside if I do not close the original message?
Thanks,
Ron