Reputation: 413
I need to set up a system to receive a soap message in it's entirety (the message is then processed by a third party app) and can't get my head round how to do this using WCF.
The format of the incoming message is as follows:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsa="http://www.w3.org/2005/08/addressing">
<s:Header>
<wsa:MessageID>3AAAF216520F</wsa:MessageID>
<wsa:Action>SendDocument</wsa:Action>
<wsa:To>~serviceURI~</wsa:To>
<wsa:From><wsa:Address>~fromServiceURI~</wsa:Address></wsa:From>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsu:Timestamp xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="D6CD5232-14CF-11DF-9423-1F9A910D4703">
<wsu:Created>~Created~</wsu:Created>
<wsu:Expires>~Expires~</wsu:Expires>
</wsu:Timestamp>
<wsse:UsernameToken>
<wsse:Username>ePAQ</wsse:Username>
</wsse:UsernameToken>
</wsse:Security>
</s:Header>
<s:Body>
<i:DistributionEnvelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">... </i:DistributionEnvelope>
</s:Body>
</s:Envelope>
Upvotes: 0
Views: 1761
Reputation: 24396
You could use a WCF universal contract:
[OperationContract(Action="*", ReplyAction="*")]
System.ServiceModel.Channels.Message ProcessMessage(System.ServiceModel.Channels.Message msg);
}
Upvotes: 1
Reputation: 1952
Take a look at this approach to see if it can help. Implement a message inspector in your WCF service project, I am giving you an example of my implementation for logging in/out soap message.
public class LogSoapMessageInterceptor : IDispatchMessageInspector
{
public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext)
{
MessageBuffer buffer = request.CreateBufferedCopy(Int32.MaxValue);
request = buffer.CreateMessage(); //this step is important http://goo.gl/u4eBT
Message message = buffer.CreateMessage(); //this step is important http://goo.gl/u4eBT
StringBuilder sb = new StringBuilder();
using (XmlWriter xw = XmlWriter.Create(sb))
{
message.WriteMessage(xw);
xw.Close();
}
Logger.Log(String.Format("Received SOAP Request:\n{0}", sb.ToString()));
return null;
}
public void BeforeSendReply(ref Message reply, object correlationState)
{
MessageBuffer buffer = reply.CreateBufferedCopy(Int32.MaxValue);
reply = buffer.CreateMessage();
Logger.Log(String.Format("Sending SOAP Reply:\n{0}", buffer.CreateMessage().ToString()));
}
}
public abstract class AbstractInterceptionBehavior<T> : IEndpointBehavior where T : IDispatchMessageInspector, new()
{
public void AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection bindingParameters)
{
}
public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)
{
}
public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
{
T inspector = new T();
endpointDispatcher.DispatchRuntime.MessageInspectors.Add(inspector);
}
public void Validate(ServiceEndpoint endpoint)
{
}
}
public class LogSoapMessageBehavior : AbstractInterceptionBehavior<LogSoapMessageInterceptor>
{
}
public class LogSoapMessageBehaviorExtensionElement : AbstractInterceptionBehaviorExtentionElement<LogSoapMessageBehavior>
{
}
//related configuration settings
<extensions>
<behaviorExtensions>
<add name="logSoapMessageBehavior"
type="xyz.com.Web.Interceptors.LogSoapMessageBehaviorExtensionElement, xyz.com" />
</behaviorExtensions>
</extensions>
Upvotes: 1