OperationContractAttribute.AsyncPattern Property

Indicates that an operation is implemented asynchronously using a Begin<methodName> and End<methodName> method pair in a service contract.

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

public bool AsyncPattern { get; set; }

Property Value

Type: System.Boolean
true if the Begin<methodName>method is matched by an End<methodName> method and can be treated by the infrastructure as an operation that is implemented as an asynchronous method pair on the service interface; otherwise, false. The default is false.

Use the AsyncPattern property to build operations that can be called asynchronously. The AsyncPattern property informs the runtime that a Begin method has a matched End method that conforms to the .NET Framework asynchronous method design pattern.

Building server asynchronous methods that implement a Windows Communication Foundation (WCF) service operation increases server scalability and performance without affecting the clients of the service, and is recommended when a service operation must return something to the client after performing a lengthy operation that can be performed asynchronously.

Clients remain unaffected because the asynchronous method pair on the server is an implementation detail that does not affect the underlying Web Services Description Language (WSDL) description of the operation. Such methods appear to clients as a single operation with <input> and correlated <output> messages. automatically routes inbound messages to the Begin<methodName> method and routes the results of the End<methodName> call to the outbound message. Client channels, therefore, can represent the method pair as either a single synchronous operation or as an asynchronous operation pair. In no case does the client representation affect the asynchronous implementation on the server in any way.

Client contracts can use the AsyncPattern property to indicate an asynchronous method pair that the client can use to invoke the operation asynchronously.


    // A service contract that is defined with an interface
    // using an aysnchronous pattern for Silverlight applications
    // and a synchronous pattern otherwise.
    [ServiceContract(
        Name = "SampleServiceContract1",
        Namespace = "http://microsoft.SL3.documentation")]
    public interface IService1
    {
#if SILVERLIGHT
        [OperationContract(AsyncPattern = true)]
        IAsyncResult BeginGetPerson(int personId, AsyncCallback callback, object state);

        Person EndGetPerson(IAsyncResult result);
#else
        [OperationContract]
        Person GetPerson(int personId);
#endif
    }

    [DataContract]
    public class Person
    {
        [DataMember]
        public string Name;
        [DataMember]
        public int Age;

    }



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

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

Community Additions

ADD
Show: