CommunicationObject.Open 方法

定義

導致通訊物件從已建立狀態轉換為已開啟狀態。Causes a communication object to transition from the created state into the opened state.

多載

Open()

導致通訊物件從已建立狀態轉換為已開啟狀態。Causes a communication object to transition from the created state into the opened state.

Open(TimeSpan)

在指定時間間隔內,讓通訊物件從已建立狀態轉換為已開啟狀態。Causes a communication object to transition from the created state into the opened state within a specified interval of time.

備註

呼叫 Open 方法時,這個方法會使 CommunicationObject 進入 Opening 狀態並呼叫 OnOpeningOpenOnOpenedWhen called, the Open method causes a CommunicationObject to enter into the Opening state and calls OnOpening, Open, and OnOpened. OnOpened 方法會將物件的狀態設定為 Open 狀態,藉此完成 Opened 方法。The OnOpened method completes the Open method by setting the state of the object to the Opened state.

Open()

導致通訊物件從已建立狀態轉換為已開啟狀態。Causes a communication object to transition from the created state into the opened state.

public:
 virtual void Open();
public void Open ();
abstract member Open : unit -> unit
override this.Open : unit -> unit
Public Sub Open ()

實作

例外狀況

通訊物件並非處於 OpenedOpening 狀態,無法修改。The communication object is not in a Opened or Opening state and cannot be modified.

通訊物件處於 ClosingClosed 狀態,無法修改。The communication object is in a Closing or Closed state and cannot be modified.

通訊物件處於 Faulted 狀態,無法修改。The communication object is in a Faulted state and cannot be modified.

已超過為作業分配的預設時間間隔,該作業未完成。The default interval of time that was allotted for the operation was exceeded before the operation was completed.

備註

當具現化 CommunicationObject 時,它一開始會處於 Created 狀態。When a CommunicationObject is instantiated, it begins in the Created state. Created 狀態下,可以設定物件 (例如可以設定屬性或註冊事件),但是仍無法傳送或接收訊息。In the Created state, the object can be configured (for example, properties can be set, or events can be registered), but it is not yet usable to send or receive messages. 呼叫 Open 方法時,這個方法會使 CommunicationObject 進入 Opening 狀態並呼叫 OnOpeningOpenOnOpenedWhen called, the Open method causes a CommunicationObject to enter into the Opening state and calls OnOpening, Open, and OnOpened. OnOpened 方法會將物件的狀態設定為 Open 狀態,藉此完成 Opened 方法。The OnOpened method completes the Open method by setting the state of the object to the Opened state.

In the

Opened 狀態下,CommunicationObject 可供使用 (例如可以接受訊息),但是無法再進行設定。Opened state, the CommunicationObject is usable (for example, messages can be received), but it is no longer configurable.

也有非同步的方式可用於開啟方法,亦即藉由呼叫 OnBeginOpen(TimeSpan, AsyncCallback, Object) 啟始,呼叫 EndOpen 完成。There is also an asynchronous version of the open method that is initiated by calling OnBeginOpen(TimeSpan, AsyncCallback, Object) and completed by calling EndOpen.

Windows 驗證的憑證擷取Credentials Capture with Windows Authentication

當使用 Windows 驗證時,服務會根據目前的內容執行緒使用認證。When using Windows authentication, credentials used by the service are based on the current context thread. 當呼叫 Open 方法時會取得認證。The credentials are obtained when the Open method is called.

注意

如果是非同步呼叫,當叫用 BeginOpen 時會擷取認證。For asynchronous calls, credentials are captured when the BeginOpen is invoked. 然而,這無法保證是實際的認證。However, the actual credentials cannot be guaranteed. 也就是說,呼叫者的認證可能會切換為其他身分識別。That is, the credentials of the caller may be switched to another identity. 如需詳細資訊,請參閱Windows 用戶端的訊息安全性For more information, see Message Security with a Windows Client.

另請參閱

Open(TimeSpan)

在指定時間間隔內,讓通訊物件從已建立狀態轉換為已開啟狀態。Causes a communication object to transition from the created state into the opened state within a specified interval of time.

public:
 virtual void Open(TimeSpan timeout);
public void Open (TimeSpan timeout);
abstract member Open : TimeSpan -> unit
override this.Open : TimeSpan -> unit
Public Sub Open (timeout As TimeSpan)

參數

timeout
TimeSpan

TimeSpan,指定必須在逾時前多久完成開啟作業。The TimeSpan that specifies how long the open operation has to complete before timing out.

實作

例外狀況

通訊物件並非處於 OpenedOpening 狀態,無法修改。The communication object is not in a Opened or Opening state and cannot be modified.

通訊物件處於 ClosingClosed 狀態,無法修改。The communication object is in a Closing or Closed state and cannot be modified.

通訊物件處於 Faulted 狀態,無法修改。The communication object is in a Faulted state and cannot be modified.

已超過為作業分配的預設時間間隔,該作業未完成。The default interval of time that was allotted for the operation was exceeded before the operation was completed.

備註

當具現化 CommunicationObject 時,它一開始會處於 Created 狀態。When a CommunicationObject is instantiated, it begins in the Created state. Created 狀態下,可以設定物件 (例如可以設定屬性或註冊事件),但是仍無法傳送或接收訊息。In the Created state, the object can be configured (for example, properties can be set, or events can be registered), but it is not yet usable to send or receive messages. 呼叫 Open 方法時,這個方法會使 CommunicationObject 進入 Opening 狀態並呼叫 OnOpeningOpenOnOpenedWhen called, the Open method causes a CommunicationObject to enter into the Opening state and calls OnOpening, Open, and OnOpened. OnOpened 方法會將物件的狀態設定為 Open 狀態,藉此完成 Opened 方法。The OnOpened method completes the Open method by setting the state of the object to the Opened state.

In the

Opened 狀態下,CommunicationObject 可供使用 (例如可以接受訊息),但是無法再進行設定。Opened state, the CommunicationObject is usable (for example, messages can be received), but it is no longer configurable.

也有非同步的方式可用於開啟方法,亦即藉由呼叫 BeginOpen 啟始,呼叫 EndOpen 完成。There is also an asynchronous version of the open method that is initiated by calling BeginOpen and completed by calling EndOpen.

適用於