I am working on a custom WCF EndpoingBehavio r 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
IEndpointBehavi or.AfterReceive Request(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.CreateM essage( message.Version ,
null, xmlReader );
// Preserve the headers of the original message
newMsg.Headers. CopyHeadersFrom ( message );
foreach (string propertyKey in message.Propert ies.Keys)
newMsg.Properti es.Add(property Key, message.Propert ies[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 (basicHttpBindi ng, HTTPS, Authentication) I immediately
get an error on the server side after the AfterReceiveReq uest method
completes and processing the message. I get the following error...
System.ObjectDi sposedException : Cannot access a disposed object.
Object name: 'System.Service Model.Security. SecurityMessage Property'.
at
System.ServiceM odel.Security.S ecurityMessageP roperty.ThrowIf Disposed()
at
System.ServiceM odel.Security.S ecurityMessageP roperty.get_Ser viceSecurityCon text()
at
System.ServiceM odel.Dispatcher .SecurityImpers onationBehavior .GetAndCacheSec urityContext(Me ssageRpc&
rpc)
at
System.ServiceM odel.Dispatcher .SecurityImpers onationBehavior .StartImpersona tion(MessageRpc &
rpc, IDisposable& impersonationCo ntext, IPrincipal&
originalPrincip al)
at
System.ServiceM odel.Dispatcher .DispatchOperat ionRuntime.Invo keBegin(Message Rpc&
rpc)
at
System.ServiceM odel.Dispatcher .ImmutableDispa tchRuntime.Proc essMessage5(Mes sageRpc&
rpc)
at
System.ServiceM odel.Dispatcher .ImmutableDispa tchRuntime.Proc essMessage4(Mes sageRpc&
rpc)
at
System.ServiceM odel.Dispatcher .ImmutableDispa tchRuntime.Proc essMessage3(Mes sageRpc&
rpc)
at
System.ServiceM odel.Dispatcher .ImmutableDispa tchRuntime.Proc essMessage2(Mes sageRpc&
rpc)
at
System.ServiceM odel.Dispatcher .ImmutableDispa tchRuntime.Proc essMessage1(Mes sageRpc&
rpc)
at System.ServiceM odel.Dispatcher .MessageRpc.Pro cess(Boolean
isOperationCont extSet)
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