This documentation is archived and is not being maintained.

Message.CreateMessage Method

Creates a message.

This member is overloaded. For complete information about this member, including syntax, usage, and examples, click a name in the overload list.

  NameDescription
Public method Static member Supported by the .NET Compact Framework CreateMessage(MessageVersion, String) Creates a message that contains a version and an action.
Public method Static member CreateMessage(MessageVersion, MessageFault, String) Creates a message that contains a SOAP fault, a version and an action.
Public method Static member CreateMessage(MessageVersion, String, Object) Creates a message with the specified version, action and body.
Public method Static member Supported by the .NET Compact Framework CreateMessage(MessageVersion, String, BodyWriter) Creates a message with a body that consists of an array of bytes.
Public method Static member CreateMessage(MessageVersion, String, XmlDictionaryReader) Creates a message with the specified version, action and body.
Public method Static member CreateMessage(MessageVersion, String, XmlReader) Creates a message using the specified reader, action and version.
Public method Static member CreateMessage(XmlDictionaryReader, Int32, MessageVersion) Creates a message using the specified reader, action and version.
Public method Static member CreateMessage(XmlReader, Int32, MessageVersion) Creates a message using the specified reader, action and version.
Public method Static member CreateMessage(MessageVersion, FaultCode, String, String) Creates a message that contains a SOAP fault, the reason for the fault, a version and an action.
Public method Static member Supported by the .NET Compact Framework CreateMessage(MessageVersion, String, Object, XmlObjectSerializer) Creates a message using the specified version, action, message body and serializer.
Public method Static member CreateMessage(MessageVersion, FaultCode, String, Object, String) Creates a message that contains a SOAP fault, a reason and the detail for the fault, version and action.
Top

This method is used to create a new copy of a message ready for sending. This static method is used to create a new copy of 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.

No code example is currently available or this language may not be supported.
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();
        }
    }
}
Show: