ערוך

שתף באמצעות


Message.CreateMessage Method

Definition

Creates a message.

Overloads

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, String, Object, XmlObjectSerializer)

Creates a message using the specified version, action, message body and serializer.

CreateMessage(MessageVersion, FaultCode, String, String)

Creates a message that contains a SOAP fault, the reason for the fault, a version and an action.

CreateMessage(XmlDictionaryReader, Int32, MessageVersion)

Creates a message using the specified reader, action and version.

CreateMessage(MessageVersion, String, XmlReader)

Creates a message using the specified reader, action and version.

CreateMessage(XmlReader, Int32, MessageVersion)

Creates a message using the specified reader, action and version.

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, 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, XmlDictionaryReader)

Creates a message with the specified version, action and body.

Examples

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();
        }
    }
}


Imports System.Collections.Generic
Imports System.Text
Imports System.ServiceModel
Imports System.ServiceModel.Channels
Imports System.Runtime.Serialization

Namespace ConsoleApplication1
    Friend Class client


        Private Shared Sub RunClient()
            'Step1: create a binding with just HTTP
            Dim binding As New CustomBinding()
            binding.Elements.Add(New HttpTransportBindingElement())
            'Step2: use the binding to build the channel factory
            Dim factory As IChannelFactory(Of IRequestChannel) = binding.BuildChannelFactory(Of IRequestChannel)(New BindingParameterCollection())
            'open the channel factory
            factory.Open()
            'Step3: use the channel factory to create a channel
            Dim channel As IRequestChannel = factory.CreateChannel(New EndpointAddress("http://localhost:8080/channelapp"))
            channel.Open()
            'Step4: create a message
            Dim requestmessage As Message = Message.CreateMessage(MessageVersion.Soap12WSAddressing10, "http://contoso.com/someaction", "This is the body data")
            'send message
            Dim replymessage As Message = channel.Request(requestmessage)
            Console.WriteLine("Reply message received")
            Console.WriteLine("Reply action: {0}", replymessage.Headers.Action)
            Dim data = replymessage.GetBody(Of 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()
        End Sub
        Public Shared Sub Main()
            Console.WriteLine("Press [ENTER] when service is ready")
            Console.ReadLine()
            RunClient()
            Console.WriteLine("Press [ENTER] to exit")
            Console.ReadLine()
        End Sub
    End Class
End Namespace

Remarks

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.

CreateMessage(MessageVersion, FaultCode, String, Object, String)

Source:
Message.cs
Source:
Message.cs
Source:
Message.cs

Creates a message that contains a SOAP fault, a reason and the detail for the fault, a version and an action.

public:
 static System::ServiceModel::Channels::Message ^ CreateMessage(System::ServiceModel::Channels::MessageVersion ^ version, System::ServiceModel::FaultCode ^ faultCode, System::String ^ reason, System::Object ^ detail, System::String ^ action);
public static System.ServiceModel.Channels.Message CreateMessage (System.ServiceModel.Channels.MessageVersion version, System.ServiceModel.FaultCode faultCode, string reason, object detail, string action);
static member CreateMessage : System.ServiceModel.Channels.MessageVersion * System.ServiceModel.FaultCode * string * obj * string -> System.ServiceModel.Channels.Message
Public Shared Function CreateMessage (version As MessageVersion, faultCode As FaultCode, reason As String, detail As Object, action As String) As Message

Parameters

version
MessageVersion

A MessageVersion object that specifies the SOAP version to use for the message.

faultCode
FaultCode

A MessageFault object that represents a SOAP fault.

reason
String

The reason of the SOAP fault.

detail
Object

The details of the SOAP fault.

action
String

A description of how the message should be processed.

Returns

A Message object for the message created.

Exceptions

version, fault, action, detail or faultCode is null.

Remarks

This static method is used to create a new copy of message ready for sending.

Applies to

CreateMessage(MessageVersion, String, Object, XmlObjectSerializer)

Source:
Message.cs
Source:
Message.cs
Source:
Message.cs

Creates a message using the specified version, action, message body and serializer.

public:
 static System::ServiceModel::Channels::Message ^ CreateMessage(System::ServiceModel::Channels::MessageVersion ^ version, System::String ^ action, System::Object ^ body, System::Runtime::Serialization::XmlObjectSerializer ^ serializer);
public static System.ServiceModel.Channels.Message CreateMessage (System.ServiceModel.Channels.MessageVersion version, string action, object body, System.Runtime.Serialization.XmlObjectSerializer serializer);
static member CreateMessage : System.ServiceModel.Channels.MessageVersion * string * obj * System.Runtime.Serialization.XmlObjectSerializer -> System.ServiceModel.Channels.Message
Public Shared Function CreateMessage (version As MessageVersion, action As String, body As Object, serializer As XmlObjectSerializer) As Message

Parameters

version
MessageVersion

A MessageVersion object that specifies the SOAP version to use for the message.

action
String

A description of how the message should be processed.

body
Object

The body of the message.

serializer
XmlObjectSerializer

A XmlObjectSerializer object used to serialize the message.

Returns

A Message object for the message created.

Exceptions

version, fault or action is null.

Remarks

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.

Applies to

CreateMessage(MessageVersion, FaultCode, String, String)

Source:
Message.cs
Source:
Message.cs
Source:
Message.cs

Creates a message that contains a SOAP fault, the reason for the fault, a version and an action.

public:
 static System::ServiceModel::Channels::Message ^ CreateMessage(System::ServiceModel::Channels::MessageVersion ^ version, System::ServiceModel::FaultCode ^ faultCode, System::String ^ reason, System::String ^ action);
public static System.ServiceModel.Channels.Message CreateMessage (System.ServiceModel.Channels.MessageVersion version, System.ServiceModel.FaultCode faultCode, string reason, string action);
static member CreateMessage : System.ServiceModel.Channels.MessageVersion * System.ServiceModel.FaultCode * string * string -> System.ServiceModel.Channels.Message
Public Shared Function CreateMessage (version As MessageVersion, faultCode As FaultCode, reason As String, action As String) As Message

Parameters

version
MessageVersion

A MessageVersion object that specifies the SOAP version to use for the message.

faultCode
FaultCode

A MessageFault object that represents a SOAP fault.

reason
String

The reason of the SOAP fault.

action
String

A description of how the message should be processed.

Returns

A Message object for the message created.

Exceptions

version, fault, action or faultCode is null.

Remarks

This static method is used to create a new copy of message ready for sending.

Applies to

CreateMessage(XmlDictionaryReader, Int32, MessageVersion)

Source:
Message.cs
Source:
Message.cs
Source:
Message.cs

Creates a message using the specified reader, action and version.

public:
 static System::ServiceModel::Channels::Message ^ CreateMessage(System::Xml::XmlDictionaryReader ^ envelopeReader, int maxSizeOfHeaders, System::ServiceModel::Channels::MessageVersion ^ version);
public static System.ServiceModel.Channels.Message CreateMessage (System.Xml.XmlDictionaryReader envelopeReader, int maxSizeOfHeaders, System.ServiceModel.Channels.MessageVersion version);
static member CreateMessage : System.Xml.XmlDictionaryReader * int * System.ServiceModel.Channels.MessageVersion -> System.ServiceModel.Channels.Message
Public Shared Function CreateMessage (envelopeReader As XmlDictionaryReader, maxSizeOfHeaders As Integer, version As MessageVersion) As Message

Parameters

envelopeReader
XmlDictionaryReader

The XmlDictionaryReader object to be used for reading the SOAP message.

maxSizeOfHeaders
Int32

The maximum size in bytes of a header.

version
MessageVersion

A valid MessageVersion value that specifies the SOAP version to use for the message.

Returns

A Message object for the message created.

Exceptions

envelopeReader or version is null.

Remarks

Message takes ownership of envelopeReader.

This method reads the envelope, buffers all the headers into the header collection, and reads up to but not including the Body start tag, and returns the message. If the method call throws an exception, it closes the reader.

The body of the returned message can then be either read or written.

The message body can be read using the GetBody methods on the returned message. The returned object encapsulates all the child elements within the Body element. The message body can be written using WriteBody or WriteMessage. Once written, it cannot be read.

Closing the message closes the underlying envelope reader.

Applies to

CreateMessage(MessageVersion, String, XmlReader)

Source:
Message.cs
Source:
Message.cs
Source:
Message.cs

Creates a message using the specified reader, action and version.

public:
 static System::ServiceModel::Channels::Message ^ CreateMessage(System::ServiceModel::Channels::MessageVersion ^ version, System::String ^ action, System::Xml::XmlReader ^ body);
public static System.ServiceModel.Channels.Message CreateMessage (System.ServiceModel.Channels.MessageVersion version, string action, System.Xml.XmlReader body);
static member CreateMessage : System.ServiceModel.Channels.MessageVersion * string * System.Xml.XmlReader -> System.ServiceModel.Channels.Message
Public Shared Function CreateMessage (version As MessageVersion, action As String, body As XmlReader) As Message

Parameters

version
MessageVersion

A MessageVersion object that specifies the SOAP version to use for the message.

action
String

A description of how the message should be processed.

body
XmlReader

The XmlReader object to be used for reading the SOAP message.

Returns

A Message object for the message created.

Exceptions

version, action or body is null.

Remarks

This static method is used to create a new copy of message ready for sending.

Applies to

CreateMessage(XmlReader, Int32, MessageVersion)

Source:
Message.cs
Source:
Message.cs
Source:
Message.cs

Creates a message using the specified reader, action and version.

public:
 static System::ServiceModel::Channels::Message ^ CreateMessage(System::Xml::XmlReader ^ envelopeReader, int maxSizeOfHeaders, System::ServiceModel::Channels::MessageVersion ^ version);
public static System.ServiceModel.Channels.Message CreateMessage (System.Xml.XmlReader envelopeReader, int maxSizeOfHeaders, System.ServiceModel.Channels.MessageVersion version);
static member CreateMessage : System.Xml.XmlReader * int * System.ServiceModel.Channels.MessageVersion -> System.ServiceModel.Channels.Message
Public Shared Function CreateMessage (envelopeReader As XmlReader, maxSizeOfHeaders As Integer, version As MessageVersion) As Message

Parameters

envelopeReader
XmlReader

The XmlReader object to be used for reading the SOAP message.

maxSizeOfHeaders
Int32

The maximum size in bytes of a header.

version
MessageVersion

A MessageVersion object that specifies the SOAP version to use for the message.

Returns

A Message object for the message created.

Exceptions

envelopeReader or version is null.

Remarks

Message takes ownership of envelopeReader.

This method reads the envelope, buffers all the headers into the header collection, and reads up to but not including the Body start tag, and returns the message. If the method call throws an exception, it closes the reader.

The body of the returned message can then be either read or written.

The message body can be read using the GetBody methods on the returned message. The returned object encapsulates all the child elements within the Body element. The message body can be written using WriteBody or WriteMessage. Once written, it cannot be read.

Closing the message closes the underlying envelope reader.

Applies to

CreateMessage(MessageVersion, String, BodyWriter)

Source:
Message.cs
Source:
Message.cs
Source:
Message.cs

Creates a message with a body that consists of an array of bytes.

public:
 static System::ServiceModel::Channels::Message ^ CreateMessage(System::ServiceModel::Channels::MessageVersion ^ version, System::String ^ action, System::ServiceModel::Channels::BodyWriter ^ body);
public static System.ServiceModel.Channels.Message CreateMessage (System.ServiceModel.Channels.MessageVersion version, string action, System.ServiceModel.Channels.BodyWriter body);
static member CreateMessage : System.ServiceModel.Channels.MessageVersion * string * System.ServiceModel.Channels.BodyWriter -> System.ServiceModel.Channels.Message
Public Shared Function CreateMessage (version As MessageVersion, action As String, body As BodyWriter) As Message

Parameters

version
MessageVersion

A MessageVersion object that specifies the SOAP version to use for the message.

action
String

A description of how the message should be processed.

body
BodyWriter

A BodyWriter of type byte.

Returns

A Message object for the message created.

Exceptions

Version, action or body is null.

Remarks

An empty message is useful for an endpoint to send an alert to another endpoint without any actual content.

Applies to

CreateMessage(MessageVersion, String, Object)

Source:
Message.cs
Source:
Message.cs
Source:
Message.cs

Creates a message with the specified version, action and body.

public:
 static System::ServiceModel::Channels::Message ^ CreateMessage(System::ServiceModel::Channels::MessageVersion ^ version, System::String ^ action, System::Object ^ body);
public static System.ServiceModel.Channels.Message CreateMessage (System.ServiceModel.Channels.MessageVersion version, string action, object body);
static member CreateMessage : System.ServiceModel.Channels.MessageVersion * string * obj -> System.ServiceModel.Channels.Message
Public Shared Function CreateMessage (version As MessageVersion, action As String, body As Object) As Message

Parameters

version
MessageVersion

A MessageVersion object that specifies the SOAP version to use for the message.

action
String

A description of how the message should be processed.

body
Object

The body of the message.

Returns

A Message object for the message created.

Exceptions

version, action or body is null.

Remarks

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.

Applies to

CreateMessage(MessageVersion, MessageFault, String)

Source:
Message.cs
Source:
Message.cs
Source:
Message.cs

Creates a message that contains a SOAP fault, a version and an action.

public:
 static System::ServiceModel::Channels::Message ^ CreateMessage(System::ServiceModel::Channels::MessageVersion ^ version, System::ServiceModel::Channels::MessageFault ^ fault, System::String ^ action);
public static System.ServiceModel.Channels.Message CreateMessage (System.ServiceModel.Channels.MessageVersion version, System.ServiceModel.Channels.MessageFault fault, string action);
static member CreateMessage : System.ServiceModel.Channels.MessageVersion * System.ServiceModel.Channels.MessageFault * string -> System.ServiceModel.Channels.Message
Public Shared Function CreateMessage (version As MessageVersion, fault As MessageFault, action As String) As Message

Parameters

version
MessageVersion

A MessageVersion object that specifies the SOAP version to use for the message.

fault
MessageFault

A MessageFault object that represents a SOAP fault.

action
String

A description of how the message should be processed.

Returns

A Message object for the message created.

Exceptions

Version, fault or action is null.

Remarks

This static method is used to create a new copy of message ready for sending.

Applies to

CreateMessage(MessageVersion, String)

Source:
Message.cs
Source:
Message.cs
Source:
Message.cs

Creates a message that contains a version and an action.

public:
 static System::ServiceModel::Channels::Message ^ CreateMessage(System::ServiceModel::Channels::MessageVersion ^ version, System::String ^ action);
public static System.ServiceModel.Channels.Message CreateMessage (System.ServiceModel.Channels.MessageVersion version, string action);
static member CreateMessage : System.ServiceModel.Channels.MessageVersion * string -> System.ServiceModel.Channels.Message
Public Shared Function CreateMessage (version As MessageVersion, action As String) As Message

Parameters

version
MessageVersion

A MessageVersion object that specifies the SOAP version to use for the message.

action
String

A description of how the message should be processed.

Returns

A Message object for the message created.

Exceptions

version or action is null.

Remarks

This static method is used to create a new copy of message ready for sending.

Applies to

CreateMessage(MessageVersion, String, XmlDictionaryReader)

Source:
Message.cs
Source:
Message.cs
Source:
Message.cs

Creates a message with the specified version, action and body.

public:
 static System::ServiceModel::Channels::Message ^ CreateMessage(System::ServiceModel::Channels::MessageVersion ^ version, System::String ^ action, System::Xml::XmlDictionaryReader ^ body);
public static System.ServiceModel.Channels.Message CreateMessage (System.ServiceModel.Channels.MessageVersion version, string action, System.Xml.XmlDictionaryReader body);
static member CreateMessage : System.ServiceModel.Channels.MessageVersion * string * System.Xml.XmlDictionaryReader -> System.ServiceModel.Channels.Message
Public Shared Function CreateMessage (version As MessageVersion, action As String, body As XmlDictionaryReader) As Message

Parameters

version
MessageVersion

A MessageVersion object that specifies the SOAP version to use for the message.

action
String

A description of how the message should be processed.

body
XmlDictionaryReader

The body of the message.

Returns

A Message object for the message created.

Exceptions

version, action or body is null.

Remarks

This static method is used to create a new copy of message ready for sending.

Applies to