Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
 IsOneWay Property
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
OperationContractAttribute..::.IsOneWay Property

Updated: November 2007

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

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

Visual Basic (Declaration)
Public Property IsOneWay As Boolean
Visual Basic (Usage)
Dim instance As OperationContractAttribute
Dim value As Boolean

value = instance.IsOneWay

instance.IsOneWay = value
C#
public bool IsOneWay { get; set; }
Visual C++
public:
property bool IsOneWay {
    bool get ();
    void set (bool value);
}
J#
/** @property */
public boolean get_IsOneWay()
/** @property */
public  void set_IsOneWay(boolean value)
JScript
public function get IsOneWay () : boolean
public function set IsOneWay (value : boolean)

Property Value

Type: System..::.Boolean

true if this method receives a request message and returns no reply message; otherwise, false. The default is false.

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. (Service applications that use reliable channels and one-way operations can detect a message delivery failure at the channel level. For details, see Reliable Sessions Overview.)

In duplex (or two-way) service-oriented applications in which the client and server communicate with each other independently, a client channel can use the IsOneWay property on its methods to indicate that the service can make one-way calls to the client that the client can treat as events. No return call or message is generated because the service does not expect any response 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 a System..::.InvalidOperationException exception is thrown.

Specifying that an operation is a one-way operation means only that there is no response message. It is possible to block if a connection cannot be made, or the outbound message is very large, or if the service cannot read inbound information fast enough. If a client requires a non-blocking call, generate AsyncPattern operations. For more information, see One-Way Services and Accessing Services Using a Client.

The following example is a service that implements a service contract that specifies three operations. Two of the methods implement two-way operations, which return underlying response messages to the caller no matter what the return value is. The third method implements an operation that receives a call (an underlying inbound message) but returns no underlying response message.

C#
[ServiceContract]
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;
  }
}

Windows Vista, Windows XP SP2, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker