OperationContractAttribute.IsOneWay Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Gets or sets a value that indicates whether an operation returns a reply message.

Namespace:  System.ServiceModel
Assembly:  System.ServiceModel (in System.ServiceModel.dll)

Syntax

'Declaration
Public Property IsOneWay As Boolean
public bool IsOneWay { get; set; }

Property Value

Type: System.Boolean
Returns Boolean.

Remarks

Use the IsOneWay property to indicate that an operation does not return a reply message. This type of operation is useful for notifications or event-style communication, especially in two-way communication. Without waiting for an underlying response message, callers of one-way operations have no direct way to detect a failure in processing the request message.

If the IsOneWay property is set to false (the default), even methods that return void result in a reply message. In this case, the infrastructure creates and sends an empty message to indicate to the caller that the method has returned. (Using this approach enables the infrastructure to send SOAP faults back to the client.) Setting IsOneWay to true is the only way to cancel the creation and dispatch of a response message.

One-way methods must not return a value or have ref or out parameters; otherwise, an InvalidOperationException exception is thrown.

Examples

    ' A service contract defined with a class
    ' for different response patterns.
    <ServiceContract(Name := "SampleServiceContract3", Namespace := "http://microsoft.SL3.documentation")> _
    Public Class OneAndTwoWay
        ' The client waits until a response message appears.
        <OperationContract> _
        Public Function MethodOne(ByVal x As Integer, <System.Runtime.InteropServices.Out()> ByRef y As Integer) As Integer
            y = 34
            Return 0
        End Function

        ' The client waits until an empty response message appears.
        <OperationContract> _
        Public Sub MethodTwo(ByVal x As Integer)
            Return
        End Sub

        ' The client returns as soon as an outbound message
        ' is queued for dispatch to the service; no response
        ' message is generated or sent.
        <OperationContract(IsOneWay := True)> _
        Public Sub MethodThree(ByVal x As Integer)
            Return
        End Sub
    End Class
// A service contract defined with a class
// for different response patterns.
[ServiceContract(
    Name = "SampleServiceContract3",
    Namespace = "http://microsoft.SL3.documentation")]
public class OneAndTwoWay
{
    // The client waits until a response message appears.
    [OperationContract]
    public int MethodOne(int x, out int y)
    {
        y = 34;
        return 0;
    }

    // The client waits until an empty response message appears.
    [OperationContract]
    public void MethodTwo(int x)
    {
        return;
    }

    // The client returns as soon as an outbound message
    // is queued for dispatch to the service; no response
    // message is generated or sent.
    [OperationContract(IsOneWay = true)]
    public void MethodThree(int x)
    {
        return;
    }
}

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.