Reputation:
How .NET framework creates SOAP message from message contract? Which serializer class is used to serialize the message contract?
Upvotes: 6
Views: 4933
Reputation: 1554
To answer the question "I wanted to see how the SOAP message will look like when message contract is serialized/formatted"
You can use a tool like Fiddler which lets you see whats going on over the wire. Here you can track the actual message xml being sent across.
Upvotes: -1
Reputation: 364389
As I understand, it is not directly used by serializer. It creates internal structure of Message
type which is then written based on MessageVersion
and selected Encoder
.
Internal structure is prepared by TypedMessageConverter
. I think it is a class responsible of message contract processing. Unfortunately, it is abstract class with internal implementation.
Because of that, message contracts works with both DataContractSerializer
and XmlSerializer
.
Upvotes: 0
Reputation:
Deep below the cover, the SOAP message is mainly constructed using SerializeReply
method of class implementing System.ServiceModel.Dispatcher.IDispatchMessageFormatter
interface. There are two internal formatters using XmlObjectSerializer
and XmlSerializer
implementations to serialize message headers and body.
Luckily, there is another, public class that provides wanted functionality. The TypedMessageConverter
internally creates dispatch message formatter in similar fashion to formatter set for a dispatch operation. It uses private GetOperationFormatter
method in Create
static method overloads in order to create instance of internal System.ServiceModel.Description.XmlMessageConverter
class.
After creating the TypedMessageConverter
implementation instance, one can pass message contract instance into ToMessage
method. Finally, call to ToString
method on Message
instance returns expected SOAP message string.
TypedMessageConverter converter = TypedMessageConverter.Create(
typeof( CustomMessage ),
"http://schemas.cyclone.com/2011/03/services/Service/GetData",
"http://schemas.cyclone.com/2011/03/data",
new DataContractFormatAttribute() { Style = OperationFormatStyle.Rpc } );
CustomMessage body = new CustomMessage()
{
// Setting of properties omitted
};
Message message = converter.ToMessage( body, MessageVersion.Soap12 );
string soapMessage = message.ToString();
Upvotes: 11
Reputation: 1039398
This will depend on your configuration. By default basicHttpBinding
and wsHttpBinding
use the DataContractSerializer class. As far as the SOAP envelopes are concerned I don't know what classes are used and I am not sure if they would be public (I might be wrong on this).
Upvotes: 1