Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Action Property
Collapse the table of content
Expand the table of content

OperationContractAttribute.Action Property

Gets or sets the WS-Addressing action of the request message.

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

public string Action { get; set; }

Property Value

Type: System.String
The action to use in generating the WS-Addressing Action header.

ExceptionCondition
ArgumentNullException

The value is null.

Use the Action property to control the action of the method's input message. Because Silverlight 5 uses this action to dispatch an incoming message to the appropriate method, messages used within a contract operation must have unique actions. The default action value is a combination of the contract namespace (the default value is "http://tempuri.org/"), the contract name (interface name or the class name, if no explicit service interface is used), the operation name, and an additional string ("Response") if the message is a correlated response. You can override this default with the Action property.

To indicate that a service operation handles all messages that the service receives but cannot be directed to a service operation, specify the value "*" (an asterisk). This type of operation, called an unmatched message handler, must have one of following method signatures, or a InvalidOperationException is thrown:

  • The service operation can take only a Message object and return a Message object.

  • The service operation can take only a Message object and return nothing (that is, return void).

NoteNote:

A service contract can have only one service operation with the Action property set to "*". Any group of service contracts hosted at the same listenUri that a service class implements can have many service operations with the Action property set to "*" when the IsInitiating property is set to false. However, only one of those service operations can have the Action property set to "*" and the IsInitiating property set to true.

For more information, see

IsInitiating.


    // A service contract defined with a class
    // for an operation that handles all messages the service receives.
    [ServiceContract(
        Name = "SampleServiceContract2",
        Namespace = "http://microsoft.SL3.documentation")]
    public class CustomerService
    {
        [OperationContract(Name = "SampleOperationContract1")]
        public int CountUsers()
        {
            return 2;
        }

        [OperationContract(Action = "*")]
        public User GetUser(int id)
        {
            if (id == 1)
            {
                return new User() { IsMember = true, Name = "Paul", Age = 24 };
            }
            else
            {
                return new User() { IsMember = false, Name = "John", Age = 64 };
            }
        }
    }

    [DataContract]
    public class User
    {
        [DataMember]
        public bool IsMember { get; set; }

        [DataMember]
        public string Name { get; set; }

        [DataMember]
        public int Age { get; set; }
    }



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:
© 2015 Microsoft