OperationContractAttribute.ProtectionLevel 屬性

定義

取得或設定值,此值指定某個作業的訊息是否須加密、簽署,或兩者都進行。Gets or sets a value that specifies whether the messages of an operation must be encrypted, signed, or both.

public:
 property System::Net::Security::ProtectionLevel ProtectionLevel { System::Net::Security::ProtectionLevel get(); void set(System::Net::Security::ProtectionLevel value); };
public System.Net.Security.ProtectionLevel ProtectionLevel { get; set; }
member this.ProtectionLevel : System.Net.Security.ProtectionLevel with get, set
Public Property ProtectionLevel As ProtectionLevel

屬性值

ProtectionLevel

其中一個 ProtectionLevel 值。One of the ProtectionLevel values. 預設為 NoneThe default is None.

例外狀況

該值不是其中一個 ProtectionLevel 值。The value is not one of the ProtectionLevel values.

備註

使用 ProtectionLevel 屬性,來控制某個作業的訊息是否需加密、簽署,或兩者都進行。Use the ProtectionLevel property to control whether the messages of an operation must be encrypted, signed, or both. 除非較窄的範圍覆寫了此值,否則這裡設定的值,會成為本作業指定的所有訊息的預設值。The value set here is the default value for all messages specified for this operation unless a narrower scope overrides this value.

請記住,執行階段的保護行為,是以下屬性的保護層級設定值的組合,這點很重要。It is important to remember that the protection behavior at runtime is the combination of the protection-level values set on the following properties. 這些屬性有階層式結構。These properties have a hierarchical structure. 除非針對較窄的範圍明確設定不同的值,否則,設定最外層的值會建立所有較窄範圍的預設值。Setting the outermost value establishes the default setting for all narrower scopes unless a different value for a narrower scope is explicitly set. 在此情況下,外部值仍為所有較窄範圍的預設值 (特別設定的範圍除外)。In this case, the outer value remains the default for all narrower scopes with the exception of that specifically set.

例如,如果 ServiceContractAttribute.ProtectionLevel 設定為 ProtectionLevel.EncryptAndSign 而且沒有其他更窄的範圍具有保護層級設定,則會加密並簽署作業合約中的所有訊息。For example, if ServiceContractAttribute.ProtectionLevel is set to ProtectionLevel.EncryptAndSign and no other narrower scopes have protection level settings, all messages in an operation contract are encrypted and signed. 但是,如果這些其中一個作業已將 ProtectionLevel 設定為 ProtectionLevel.Sign,則會簽署該作業的訊息,但是合約中的其他所有訊息都會經過加密並簽署。If, however, one of those operations has the ProtectionLevel set to ProtectionLevel.Sign, then the messages for that operation are signed but all other messages in the contract are encrypted and signed.

如需保護層級及其假設和範圍的詳細資訊,請參閱 瞭解保護層級For details about protection levels and their assumptions and scopes, see Understanding Protection Level.

設定這些值的範圍如下:The scopes at which these values are set are:

ServiceContractAttribute.ProtectionLevel

OperationContractAttribute.ProtectionLevel

FaultContractAttribute.ProtectionLevel

MessageContractAttribute.ProtectionLevel

MessageContractMemberAttribute.ProtectionLevelSystem.ServiceModel.MessageHeaderAttribute 屬性。The MessageContractMemberAttribute.ProtectionLevel property on System.ServiceModel.MessageHeaderAttribute.

MessageContractMemberAttribute.ProtectionLevelSystem.ServiceModel.MessageBodyMemberAttribute 屬性。The MessageContractMemberAttribute.ProtectionLevel property on System.ServiceModel.MessageBodyMemberAttribute.

當合約上未明確指定保護層級,而且基礎繫結可支援安全性 (不論是在傳輸層級或訊息層級) 時,整個合約的有效保護層級會是 ProtectionLevel.EncryptAndSignWhen there is no protection level explicitly specified on the contract and the underlying binding supports security (whether at the transport or message level), the effective protection level for the whole contract is ProtectionLevel.EncryptAndSign. 如果繫結不支援安全性 (例如,BasicHttpBinding),整個合約的有效 System.Net.Security.ProtectionLevelProtectionLevel.NoneIf the binding does not support security (such as BasicHttpBinding), the effective System.Net.Security.ProtectionLevel is ProtectionLevel.None for the whole contract. 結果便是根據端點繫結的不同,用戶端可以要求不同的訊息或傳輸層級的安全性保護,即使當合約指定 ProtectionLevel.None 時亦然。The result is that depending upon the endpoint binding, clients can require different message or transport level security protection even when the contract specifies ProtectionLevel.None.

適用於