2 using System.Collections.Generic;
3 using System.Collections.ObjectModel;
4 using System.ServiceModel;
5 using System.ServiceModel.Channels;
6 using System.ServiceModel.Description;
7 using System.ServiceModel.Dispatcher;
9 namespace System.ServiceModel.Routing
11 public class SoapProcessingBehavior : IEndpointBehavior
13 class MessageInspector : IClientMessageInspector
15 public MessageInspector (SoapProcessingBehavior owner, ServiceEndpoint endpoint)
17 this.endpoint = endpoint;
20 ServiceEndpoint endpoint;
22 public object BeforeSendRequest (ref Message request, IClientChannel channel)
24 // See "Request processing" at http://msdn.microsoft.com/en-us/library/ee517422%28VS.100%29.aspx
26 var original = request;
27 var msg = Message.CreateMessage (endpoint.Binding.MessageVersion, request.Headers.Action, request.GetReaderAtBodyContents ());
28 // The above page does not explain, but it should do copy headers (other than addressing ones, to be removed later).
29 msg.Headers.Action = null;
30 msg.Headers.CopyHeadersFrom (request);
31 msg.Headers.To = null;
32 msg.Headers.From = null;
33 msg.Headers.FaultTo = null;
34 msg.Headers.RelatesTo = null;
35 msg.Properties.CopyProperties (request.Properties);
41 public void AfterReceiveReply (ref Message reply, object correlationState)
43 // See "Response processing" at http://msdn.microsoft.com/en-us/library/ee517422%28VS.100%29.aspx
45 Message original = (Message) correlationState;
47 var msg = Message.CreateMessage (original.Version, reply.Headers.Action, reply.GetReaderAtBodyContents ());
48 // The above page does not explain, but it should do copy headers (other than addressing ones, to be removed later).
49 msg.Headers.Action = null;
50 msg.Headers.CopyHeadersFrom (reply);
52 msg.Headers.To = null;
53 msg.Headers.From = null;
54 msg.Headers.FaultTo = null;
55 msg.Headers.RelatesTo = null;
57 msg.Properties.CopyProperties (reply.Properties);
62 public SoapProcessingBehavior ()
64 ProcessMessages = true;
67 public bool ProcessMessages { get; set; }
69 public void AddBindingParameters (ServiceEndpoint endpoint, BindingParameterCollection bindingParameters)
71 // nothing to do here.
74 public void ApplyClientBehavior (ServiceEndpoint endpoint, ClientRuntime clientRuntime)
78 clientRuntime.MessageInspectors.Add (new MessageInspector (this, endpoint));
81 public void ApplyDispatchBehavior (ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
83 throw new NotSupportedException (); // ... right? I assume it is not for services.
86 public void Validate (ServiceEndpoint endpoint)