OperationContractAttribute.ReplyAction 屬性


取得或設定作業之回覆訊息的 SOAP 動作值。Gets or sets the value of the SOAP action for the reply message of the operation.

 property System::String ^ ReplyAction { System::String ^ get(); void set(System::String ^ value); };
public string ReplyAction { get; set; }
member this.ReplyAction : string with get, set
Public Property ReplyAction As String



回覆訊息的 SOAP 動作值。The value of the SOAP action for the reply message.



下列範例中的服務使用 ActionReplyAction 屬性,明確控制輸入與輸出 (或回覆) 訊息的 SOAP 動作。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. 它亦使用 Name 屬性來宣告中繼資料內所公開的作業名稱。It also uses the Name property to declare the name of the operation as exposed in metadata.

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

namespace Microsoft.WCF.Documentation
  public interface ISampleService{

    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());
Imports System.ServiceModel
Imports System.ServiceModel.Channels
Imports 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")> _
        Function SampleMethod(ByVal msg As String) As String

    <OperationContractAttribute(Action := "*")> _
    Sub UnrecognizedMessageHandler(ByVal msg As Message)
  End Interface

  Friend Class SampleService
      Implements ISampleService
    Public Function SampleMethod(ByVal msg As String) As String Implements ISampleService.SampleMethod
      Console.WriteLine("Called with: {0}", msg)
         Return "The service greets you: " & msg
    End Function

    Public Sub UnrecognizedMessageHandler(ByVal msg As Message) Implements ISampleService.UnrecognizedMessageHandler
      Console.WriteLine("Unrecognized message: " & msg.ToString())
    End Sub
  End Class
End Namespace


除了指定回覆訊息的動作標頭之特定值之外,您亦可指定 "*" (星號) 字串。In addition to specifying a particular value for the action header of the reply message, you can also specify the string "*" (an asterisk). 在服務中指定星號會指示 WCF 不要將回復動作加入至訊息,如果您要直接針對訊息進行程式設計,這就很有用。Specifying an asterisk in the service instructs WCF not to add a reply action to the message, which is useful if you are programming against messages directly. 在用戶端應用程式中指定星號,會指示 WCF 不要驗證回復動作。Specifying an asterisk in a client application instructs WCF not to validate the reply action.