ServiceContractAttribute.ProtectionLevel 屬性

定義

指定合約繫結是否必須支援 ProtectionLevel 屬性的值。

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 值。 預設值為 None

例外狀況

該值不是其中一個 ProtectionLevel 值。

備註

ProtectionLevel使用 屬性來指定合約系結需要加密、數位簽章,或公開合約之端點的兩者之程度。 這裡設定的值,會成為所有作業訊息 (包括錯誤) 的預設值。

請記住,執行階段的保護行為,是以下屬性的保護層級設定值的組合,這點很重要。 這些屬性有階層式結構。 除非針對較窄的範圍明確設定不同的值,否則,設定最外層的值會建立所有較窄範圍的預設值。 在此情況下,外部值仍為所有較窄範圍的預設值 (特別設定的範圍除外)。

例如,如果 ServiceContractAttribute.ProtectionLevel 設定為 ProtectionLevel.EncryptAndSign 而且沒有其他更窄的範圍具有保護層級設定,則會加密並簽署作業合約中的所有訊息。 但是,如果這些其中一個作業已將 OperationContractAttribute 設定為 ProtectionLevel.Sign,則會簽署該作業的訊息,但是合約中的其他所有訊息都會經過加密並簽署。

如需保護層級及其假設和範圍的詳細資訊,請參閱 瞭解保護等級

設定這些值的範圍如下:

ServiceContractAttribute.ProtectionLevel

OperationContractAttribute.ProtectionLevel

FaultContractAttribute.ProtectionLevel

MessageContractAttribute.ProtectionLevel

MessageContractMemberAttribute.ProtectionLevelSystem.ServiceModel.MessageHeaderAttribute 屬性。

MessageContractMemberAttribute.ProtectionLevelSystem.ServiceModel.MessageBodyMemberAttribute 屬性。

當合約上未明確指定保護層級,而且基礎繫結可支援安全性 (不論是在傳輸層級或訊息層級) 時,整個合約的有效保護層級會是 ProtectionLevel.EncryptAndSign。 如果繫結不支援安全性 (例如,BasicHttpBinding),整個合約的有效 System.Net.Security.ProtectionLevelProtectionLevel.None。 結果便是根據端點繫結的不同,用戶端可以要求不同的訊息或傳輸層級的安全性保護,即使當合約指定 ProtectionLevel.None 時亦然。

適用於