Message.CreateMessage Method
Creates a message.
Assembly: System.ServiceModel (in System.ServiceModel.dll)
| Name | Description | |
|---|---|---|
![]() ![]() | CreateMessage(MessageVersion, FaultCode, String, Object, String) | Creates a message that contains a SOAP fault, a reason and the detail for the fault, a version and an action. |
![]() ![]() | CreateMessage(MessageVersion, FaultCode, String, String) | Creates a message that contains a SOAP fault, the reason for the fault, a version and an action. |
![]() ![]() | CreateMessage(MessageVersion, MessageFault, String) | Creates a message that contains a SOAP fault, a version and an action. |
![]() ![]() | CreateMessage(MessageVersion, String) | Creates a message that contains a version and an action. |
![]() ![]() | CreateMessage(MessageVersion, String, BodyWriter) | Creates a message with a body that consists of an array of bytes. |
![]() ![]() | CreateMessage(MessageVersion, String, Object) | Creates a message with the specified version, action and body. |
![]() ![]() | CreateMessage(MessageVersion, String, Object, XmlObjectSerializer) | Creates a message using the specified version, action, message body and serializer. |
![]() ![]() | CreateMessage(MessageVersion, String, XmlDictionaryReader) | Creates a message with the specified version, action and body. |
![]() ![]() | CreateMessage(MessageVersion, String, XmlReader) | Creates a message using the specified reader, action and version. |
![]() ![]() | CreateMessage(XmlDictionaryReader, Int32, MessageVersion) | Creates a message using the specified reader, action and version. |
![]() ![]() | CreateMessage(XmlReader, Int32, MessageVersion) | Creates a message using the specified reader, action and version. |
This method is used to create a new copy of a message ready for sending.
When working with JSON messages use the CreateMessage(MessageVersion, String, Object, XmlObjectSerializer) method, the CreateMessage(MessageVersion, String, Object) method does not work with JSON messages.
The following code example shows a client that uses the channel factory to send a message and read the reply.
using System; using System.Collections.Generic; using System.Text; using System.ServiceModel; using System.ServiceModel.Channels; using System.Runtime.Serialization; namespace ConsoleApplication1 { class client { static void RunClient() { //Step1: create a binding with just HTTP CustomBinding binding = new CustomBinding(); binding.Elements.Add(new HttpTransportBindingElement()); //Step2: use the binding to build the channel factory IChannelFactory<IRequestChannel> factory = binding.BuildChannelFactory<IRequestChannel>( new BindingParameterCollection()); //open the channel factory factory.Open(); //Step3: use the channel factory to create a channel IRequestChannel channel = factory.CreateChannel( new EndpointAddress("http://localhost:8080/channelapp")); channel.Open(); //Step4: create a message Message requestmessage = Message.CreateMessage( MessageVersion.Soap12WSAddressing10, "http://contoso.com/someaction", "This is the body data"); //send message Message replymessage = channel.Request(requestmessage); Console.WriteLine("Reply message received"); Console.WriteLine("Reply action: {0}", replymessage.Headers.Action); string data = replymessage.GetBody<string>(); Console.WriteLine("Reply content: {0}", data); //Step5: don't forget to close the message requestmessage.Close(); replymessage.Close(); //don't forget to close the channel channel.Close(); //don't forget to close the factory factory.Close(); } public static void Main() { Console.WriteLine("Press [ENTER] when service is ready"); Console.ReadLine(); RunClient(); Console.WriteLine("Press [ENTER] to exit"); Console.ReadLine(); } } }

