Can a WCF web service access raw SOAP message Header and Body as XML data?

958 views Asked by At

I need to build a web service in C# which will receive a SOAP 1.1 message where the <Envelope><Header> and <Envelope><Body> will contain only complex XML data.

In WSE (according to this Microsoft page), creating a SOAP web service to handle this type of message seems fairly straight forward :

class MyReceiver : SoapReceiver
{
    protected override void Receive(SoapEnvelope message)
    {
        // Do something with the message
        // such as display its contents.
    }
}

But, since WSE is being depreciated, I would like to build this service using WCF.

The WCF examples I find, though, seem to be of the variety where a specific set of parameters are passed to a specific method.

[OperationContract]
string GetData(int value);

Is there a way using WCF to create a web service which can receive raw SOAP 1.1 messages and provide access to the <Envelope><Header> and <Envelope><Body> sections as XML elements or XML streams?

1

There are 1 answers

1
Konrad Kokosa On

To process raw SOAP messages you should use Message class, which represents raw message. Simply create your operation contract that accepts and returns it:

public Message ProcessMessage(Message msg);

then you will have Message.Headers or Message.GetBody methods. There is also a Message.Version if you want to check if it is whether SOAP 1.1 or 1.2.