Export (0) Print
Expand All

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 */
public String get_Action ()

/** @property */
public void set_Action (String value)

public function get Action () : String

public function set Action (value : String)

Not applicable.

Property Value

The action to use in generating the WS-Addressing Action header.

Exception typeCondition

ArgumentNullException

The value is a null reference (Nothing in Visual Basic).

Use the Actionproperty to control the action of the method's input message. Because WCF 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 details, see IsInitiating.

The following example is a service that uses the Action and ReplyAction properties to explicitly control the SOAP actions of both the input and output (or reply) messages, and the Name property to control the name of the operation in metadata. Finally, the application also uses an Action value of "*" to indicate a method that handles unrecognized messages.

using System;
using System.Collections.Generic;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.Text;

namespace Microsoft.WCF.Documentation
{
  [ServiceContract(Namespace="http://Microsoft.WCF.Documentation")]
  public interface ISampleService{

    [OperationContract(
      Action="http://Microsoft.WCF.Documentation/OperationContractMethod",
      Name="OCAMethod",
      ReplyAction="http://Microsoft.WCF.Documentation/ResponseToOCAMethod"
    )]
    string SampleMethod(string msg);

    [OperationContractAttribute(Action = "*")]
    void UnrecognizedMessageHandler(Message msg);
  }

  class SampleService : ISampleService
  {
    public string  SampleMethod(string msg)
    {
      Console.WriteLine("Called with: {0}", msg);
 	    return "The service greets you: " + msg;
    }

    public void UnrecognizedMessageHandler(Message msg)
    {
      Console.WriteLine("Unrecognized message: " + msg.ToString());
    }
  }
}

A service that implements this contract sends messages that look like the following example:

<s:Envelope xmlns:a="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:s="http://www.w3.org/2003/05/soap-envelope">
  <s:Header>
    <a:Action s:mustUnderstand="1">http://Microsoft.WCF.Documentation/ResponseToOCAMethod</a:Action> 
  </s:Header>
  <s:Body>
    <OCAMethodResponse xmlns="http://Microsoft.WCF.Documentation">
      <OCAMethodResult>The service greets you: Hello!</OCAMethodResult> 
    </OCAMethodResponse>
  </s:Body>
</s:Envelope>

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0

Community Additions

ADD
Show:
© 2014 Microsoft