InvokeOperation Class

[WCF RIA Services Version 1 Service Pack 2 is compatible with either .NET framework 4 or .NET Framework 4.5, and with either Silverlight 4 or Silverlight 5.]

Represents an asynchronous invoke operation.

Inheritance Hierarchy

System.Object
System.ServiceModel.DomainServices.Client.OperationBase
System.ServiceModel.DomainServices.Client.InvokeOperation
System.ServiceModel.DomainServices.Client.InvokeOperation<TValue>

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

Syntax

'Declaration
Public Class InvokeOperation _
    Inherits OperationBase
'Usage
Dim instance As InvokeOperation
public class InvokeOperation : OperationBase
public ref class InvokeOperation : public OperationBase
type InvokeOperation =  
    class
        inherit OperationBase
    end
public class InvokeOperation extends OperationBase

The InvokeOperation type exposes the following members.

Properties

Name Description
Public property CanCancel Gets a value that indicates whether this OperationBase is currently in a state that enables it to be canceled. (Inherited from OperationBase.)
Public property Error Gets the operation error if the operation failed. (Inherited from OperationBase.)
Public property HasError Gets a value that indicates whether the operation failed. (Inherited from OperationBase.)
Public property IsCanceled Gets a value that indicates whether this operation has been canceled. (Inherited from OperationBase.)
Public property IsComplete Gets a value that indicates whether this operation has completed. (Inherited from OperationBase.)
Public property IsErrorHandled Gets or sets a value that indicates whether the operation error has been handled. (Inherited from OperationBase.)
Public property OperationName Gets the name of the operation.
Public property Parameters Gets the collection of parameters to the operation.
Protected property Result Gets the DomainClientResult for this operation.
Protected property SupportsCancellation Gets a value indicating whether this operation supports cancellation. (Overrides OperationBase.SupportsCancellation.)
Public property UserState Gets the optional user state for this operation. (Inherited from OperationBase.)
Public property ValidationErrors Gets the validation errors for this operation.
Public property Value Gets the return value for the invoke operation.

Top

Methods

Name Description
Public method Cancel Cancels the operation. (Inherited from OperationBase.)
Protected method CancelCore Invokes the cancel callback. (Overrides OperationBase.CancelCore().)
Protected method Complete(Exception) Completes a failed operation with the specified error. (Inherited from OperationBase.)
Protected method Complete(Object) Completes a successful operation with the specified result. (Inherited from OperationBase.)
Public method Equals (Inherited from Object.)
Protected method Finalize (Inherited from Object.)
Public method GetHashCode (Inherited from Object.)
Public method GetType (Inherited from Object.)
Protected method InvokeCompleteAction Invokes the completion callback. (Overrides OperationBase.InvokeCompleteAction().)
Public method MarkErrorAsHandled Specifies that an error encountered in an operation is handled. (Inherited from OperationBase.)
Protected method MemberwiseClone (Inherited from Object.)
Protected method OnPropertyChanged Called when the value of a property changes. (Inherited from OperationBase.)
Protected method RaisePropertyChanged Raises the System#ComponentModel#INotifyPropertyChanged#PropertyChanged() event. (Inherited from OperationBase.)
Public method ToString (Inherited from Object.)

Top

Events

Name Description
Public event Completed Occurs when the operation completes. (Inherited from OperationBase.)

Top

Explicit Interface Implementations

Name Description
Explicit interface implemetationPrivate event INotifyPropertyChanged.PropertyChanged Occurs when a property value changes. (Inherited from OperationBase.)

Top

Examples

Partial Public Class MainPage
    Inherits UserControl

    ' Create the DomainContext for the DomainService
    Private _customerContext As CustomerDomainContext = New CustomerDomainContext()

    Friend invokeOp As InvokeOperation = New InvokeOperation()

    ' In this example, the value of the invoke operations is supposed to be a string
    Friend result As Integer


    Dim opEx As DomainOperationException = New DomainOperationException()

    Public Function MainPage()
        InitializeComponent()

        'Set invokeOp equal to _customerContext.CountCustomers
        invokeOp = _customerContext.CountCustomers(OnInvokeCompleted, Nothing)

        Dim query As EntityQuery(Of Customer) =
            From c In _customerContext.GetCustomersQuery
            Where c.Phone.StartsWith("583")
            Order By c.LastName
            Select c

        Dim loadOp As LoadOperation(Of Customer) = this._customerContext.Load(query, LoadBehavior.MergeIntoCurrent, False)

        opEx = New DomainOperationException("Validation Error",
                                            OperationErrorStatus.ValidationFailed,
                                            326)
        If loadOp.ValidationErrors <> Nothing Then
            Throw opEx
        End If

        Dim qr As QueryResult(Of Customer) = New QueryResult(Of Customer)()

        CustomerGrid.ItemsSource = qr.IncludedResults

    End Function

    'Create a method for handling the InvokeOperations onCompleted.
    Private Function OnInvokeCompleted(ByVal invOp As InvokeOperation)
        If invOp.HasError = True Then
            If invOp.ValidationErrors <> Nothing Then
                Throw opEx
            Else
                MessageBox.Show(String.Format("An Error Occured" + vbCrLf + _
                                              "Error Message: {0}" + vbCrLf + _
                                              "InnerException: {1}", invOp.Message, invOp.InnerException.Message))
                invOp.MarkErrorAsHandled()
            End If

        Else
            result = invokeOp.Value
        End If
    End Function

End Class
public partial class MainPage : UserControl
{
    // Create the DomainContext for the DomainService
    private CustomerDomainContext _customerContext = new CustomerDomainContext();

    InvokeOperation invokeOp = new InvokeOperation();
    string result;

    DomainOperationException opEx = new DomainOperationException();

    public MainPage()
    {
        InitializeComponent();

        // Set invokeOp equal to _customerContext.CountCustomers
        invokeOp = _customerContext.CountCustomers(OnInvokeCompleted, null);

        EntityQuery<Customer> query =
            from c in _customerContext.GetCustomersQuery()
            where c.Phone.StartsWith("583")
            orderby c.LastName
            select c;
        LoadOperation<Customer> loadOp = this._customerContext.Load(query, LoadBehavior.MergeIntoCurrent, false);

        opEx = new DomainOperationException(
            "Validation Error",
            OperationErrorStatus.ValidationFailed,
            0x000024FA);

        if (loadOp.ValidationErrors != null)
        {
            throw opEx;
        }

        QueryResult<Customer> qr = new QueryResult<Customer>();

        CustomerGrid.ItemsSource = qr.IncludedResults;
    }

    // Create a method for Handling the InvokeOperation Completed.
    private void OnInvokeCompleted(InvokeOperation invOp)
    {
        if (invOp.HasError)
        {
            if (invOp.ValidationErrors != null)
            {
                throw opEx;
            }
            else
            {
                MessageBox.Show(string.Format("An Error Occured/nError Message: {0}/nInner Exception Message: {1}",
                                              invOp.Error.Message,
                                              invOp.Error.InnerException.Message));
                invOp.MarkErrorAsHandled();
            }
        }
        else
        {
            // Convert the value of invokeOp which is an integer to a string for output
            // in the result field.
            result = invokeOp.Value.ToString();
            MessageBox(string.Format("InvokeOperation '{0}' has completed", invokeOp.OperationName);

        }
    }
}

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.

See Also

Reference

System.ServiceModel.DomainServices.Client Namespace