OperationContractAttribute.Action 속성

정의

요청 메시지의 WS-Addressing 동작을 가져오거나 설정합니다.

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

속성 값

String

WS-Addressing 동작 헤더를 생성하는 데 사용할 동작입니다.

예외

값이 null인 경우

예제

다음 예제는 입력 및 ReplyAction 출력(또는 회신) 메시지의 SOAP 작업을 명시적으로 제어하는 속성과 Name 메타데이터에서 작업의 이름을 제어하는 속성을 사용하는 Action 서비스입니다. 또한 애플리케이션에서는 Action 값으로 "*"를 사용하여 인식할 수 없는 메시지를 처리하는 메서드를 나타냅니다.

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());
    }
  }
}
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

이 계약을 구현하는 서비스는 다음 예제와 같은 메시지를 보냅니다.

<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>

설명

속성을 Action 사용하여 메서드의 입력 메시지 동작을 제어합니다. WCF는 이 작업을 사용하여 들어오는 메시지를 적절한 메서드로 디스패치하기 때문에 계약 작업 내에서 사용되는 메시지에는 고유한 작업이 있어야 합니다. 기본 작업 값은 계약 네임스페이스(기본값), "http://tempuri.org/"계약 이름(인터페이스 이름 또는 클래스 이름, 명시적 서비스 인터페이스가 사용되지 않는 경우), 작업 이름 및 추가 문자열("응답")(메시지가 상관 관계가 있는 응답인 경우)의 조합입니다. 이 기본값을 속성으로 재정의할 Action 수 있습니다.

서비스 작업이 수신하지만 서비스 작업으로 전달될 수 없는 모든 메시지를 처리함을 나타내려면 "*" 값(별표)을 지정합니다. 일치하지 않는 메시지 처리기라고 하는 이 유형의 작업에는 다음 메서드 서명 중 하나가 있거나 throw InvalidOperationException 되어야 합니다.

  • 서비스 작업은 개체만 사용하고 개체를 Message 반환할 Message 수 있습니다.

  • 서비스 작업은 개체만 Message 사용하고 아무 것도 반환하지 않습니다(즉, 반환 void).

참고

서비스 계약에는 속성이 "*"로 Action 설정된 하나의 서비스 작업만 있을 수 있습니다. 서비스 클래스가 구현하는 동일한 listenUri에서 호스트되는 모든 서비스 계약 그룹에는 속성false이 설정된 경우 "*"IsInitiating로 설정된 여러 서비스 작업이 Action 있을 수 있습니다. 그러나 이러한 서비스 작업 중 하나만 속성을 "*"IsInitiating로 설정하고 속성을 true로 설정할 수 있습니다Action. 자세한 내용은 IsInitiating를 참조하세요.

적용 대상