SoapSender.Send Method
Transmits a SoapEnvelope via the TCP or HTTP protocol.
Namespace: Microsoft.Web.Services2.Messaging
Assembly: Microsoft.Web.Services2 (in microsoft.web.services2.dll)
Usage
'Usage
Dim envelope As SoapEnvelope
Dim soapSender1 As SoapSender
soapSender1.Send(envelope)
Syntax
'Declaration
Public Overridable Sub Send( _
ByVal envelope As SoapEnvelope _
)
public virtual void Send(
SoapEnvelope envelope
);
public: Void Send(
SoapEnvelope^ envelope
);
public void Send(
SoapEnvelope envelope
);
public function Send(
envelope : SoapEnvelope
);
Parameters
- envelope
A SoapEnvelope that represents the SOAP message.
Example
The following code example shows how to use a SoapSender to send a SOAP message with the TCP protocol to a destination specified in a text box named DestinationHostNameTextBox
.
Dim DestinationUri As New Uri("soap.tcp://" + DestinationHostNameTextBox.Text + "/MyReceiver")
Dim Destination As New Addressing.EndpointReference(DestinationUri)
Dim MySender As New SoapSender(Destination)
Dim envelope As New SoapEnvelope()
envelope.Context.Addressing.Action = New Addressing.Action("myReceiver")
Dim body As XmlElement = envelope.CreateBody()
body.InnerText = MessageTextBox.Text
MySender.Destination = Destination
MySender.Send(envelope)
End If '</snippet5>
End Sub 'SendButton_Click
End Class 'Form1
'
' class MyReceiver : SoapReceiver
' {
' protected override void Receive( SoapEnvelope message )
' {
' TheForm.UpdateList(message.Body.InnerText);
' }
'
' public Form1 TheForm;
' }
'
'
Class MyReceiver
Inherits SoapReceiver
Protected Overloads Overrides Sub Receive(message As SoapEnvelope)
End Sub 'Receive
End Class 'MyReceiver 'Processing of message goes here
Class MyClient
Inherits SoapClient
Public Sub New(destination As Uri)
MyBase.New(destination)
End Sub 'New
<SoapMethod("RequestResponseMethod")> _
Public Function RequestResponseMethod(envelope As SoapEnvelope) As SoapEnvelope
Return MyBase.SendRequestResponse("RequestResponseMethod", envelope)
End Function 'RequestResponseMethod
End Class 'MyClient
Class MyService
Inherits SoapService
<SoapMethod("RequestResponseMethod")> _
Public Function RequestResponseMethod(envelope As SoapEnvelope) As SoapEnvelope
Dim message As String = "Response from " + System.Net.Dns.GetHostName()
Dim response As New SoapEnvelope()
response.SetBodyObject(message)
Return response
End Function 'RequestResponseMethod
End Class 'MyService
Uri Destination = new Uri( "soap.tcp://" + DestinationHostNameTextBox.Text + "/MyReceiver");
SoapSender Sender = new SoapSender(Destination);
SoapEnvelope envelope = new SoapEnvelope();
envelope.Context.Addressing.Action = "myReceiver";
XmlElement body = envelope.CreateBody();
body.InnerText = MessageTextBox.Text;
Sender.Destination = Destination;
Sender.Send(envelope);
Exceptions
Exception type | Condition |
---|---|
System.ArgumentNullException | envelope is null. |
System.ArgumentException | The Action property of the SoapContext for envelopeis null. -or- An attempt to reprocess a SoapEnvelope or SoapContext was detected. |
System.InvalidOperationException | The Destination is null. |
Remarks
In order to call the send method, the destination URI must first be specified in the SoapSender constructor. This can be either an HTTP or a TCP URI.
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Platforms
Development Platforms
Windows XP Home Edition, Windows XP Professional, Windows Server 2003, Windows Longhorn, and Windows 2000
Target Platforms
Windows 2000, Windows 2000 Server, Windows 2000 Advanced Server, Windows XP Home Edition, Windows XP Professional, Windows Server 2003, Windows Longhorn, Pocket PC, Windows CE, Smart Phone
See Also
Reference
SoapSender Class
Microsoft.Web.Services2.Messaging Namespace