| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- //------------------------------------------------------------
- // Copyright (c) Microsoft Corporation. All rights reserved.
- //------------------------------------------------------------
- namespace System.ServiceModel
- {
- using System.Net.Security;
- using System.Reflection;
- using System.ServiceModel.Description;
- using System.ServiceModel.Security;
- [AttributeUsage(ServiceModelAttributeTargets.OperationContract)]
- public sealed class OperationContractAttribute : Attribute
- {
- string name = null;
- string action = null;
- string replyAction = null;
- bool asyncPattern = false;
- bool isInitiating = true;
- bool isTerminating = false;
- bool isOneWay = false;
- ProtectionLevel protectionLevel = ProtectionLevel.None;
- bool hasProtectionLevel = false;
- public string Name
- {
- get { return this.name; }
- set
- {
- if (value == null)
- {
- throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("value");
- }
- if (value == "")
- {
- throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value",
- SR.GetString(SR.SFxNameCannotBeEmpty)));
- }
- this.name = value;
- }
- }
- internal const string ActionPropertyName = "Action";
- public string Action
- {
- get { return this.action; }
- set
- {
- if (value == null)
- {
- throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("value");
- }
- this.action = value;
- }
- }
- internal const string ProtectionLevelPropertyName = "ProtectionLevel";
- public ProtectionLevel ProtectionLevel
- {
- get
- {
- return this.protectionLevel;
- }
- set
- {
- if (!ProtectionLevelHelper.IsDefined(value))
- throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value"));
- this.protectionLevel = value;
- this.hasProtectionLevel = true;
- }
- }
- public bool HasProtectionLevel
- {
- get { return this.hasProtectionLevel; }
- }
- internal const string ReplyActionPropertyName = "ReplyAction";
- public string ReplyAction
- {
- get { return this.replyAction; }
- set
- {
- if (value == null)
- {
- throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("value");
- }
- this.replyAction = value;
- }
- }
- public bool AsyncPattern
- {
- get { return this.asyncPattern; }
- set { this.asyncPattern = value; }
- }
- public bool IsOneWay
- {
- get { return this.isOneWay; }
- set { this.isOneWay = value; }
- }
- public bool IsInitiating
- {
- get { return this.isInitiating; }
- set { this.isInitiating = value; }
- }
- public bool IsTerminating
- {
- get { return this.isTerminating; }
- set { this.isTerminating = value; }
- }
- internal bool IsSessionOpenNotificationEnabled
- {
- get
- {
- return this.Action == OperationDescription.SessionOpenedAction;
- }
- }
- internal void EnsureInvariants(MethodInfo methodInfo, string operationName)
- {
- if (this.IsSessionOpenNotificationEnabled)
- {
- if (!this.IsOneWay
- || !this.IsInitiating
- || methodInfo.GetParameters().Length > 0)
- {
- throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(
- SR.GetString(SR.ContractIsNotSelfConsistentWhenIsSessionOpenNotificationEnabled, operationName, "Action", OperationDescription.SessionOpenedAction, "IsOneWay", "IsInitiating")));
- }
- }
- }
- }
- }
|