2010-10-22 3 views
3

У меня есть ссылка WebService (.NET CF 3.5) на основе SoapHttpClientProtocol. Мой вопрос: есть ли способ определить, установлено ли соединение с WebService, кроме вызова веб-метода? Могу ли я проверить в любое время, что базовое соединение установлено и получить его статус?SoapHttpClientProtocol/HttpWebClientProtocol status status

С уважением

+0

Вам нужно сделать это определение с помощью кода? –

ответ

1

Вы можете проверить состояние связи на клиенте.

using (XServiceSoapClient client = new XServiceSoapClient()) 
{ 
    client.State; 
} 

public enum CommunicationState 
{ 
    // Summary: 
    //  Indicates that the communication object has been instantiated and is configurable, 
    //  but not yet open or ready for use. 
    Created = 0, 
    // 
    // Summary: 
    //  Indicates that the communication object is being transitioned from the System.ServiceModel.CommunicationState.Created 
    //  state to the System.ServiceModel.CommunicationState.Opened state. 
    Opening = 1, 
    // 
    // Summary: 
    //  Indicates that the communication object is now open and ready to be used. 
    Opened = 2, 
    // 
    // Summary: 
    //  Indicates that the communication object is transitioning to the System.ServiceModel.CommunicationState.Closed 
    //  state. 
    Closing = 3, 
    // 
    // Summary: 
    //  Indicates that the communication object has been closed and is no longer 
    //  usable. 
    Closed = 4, 
    // 
    // Summary: 
    //  Indicates that the communication object has encountered an error or fault 
    //  from which it cannot recover and from which it is no longer usable. 
    Faulted = 5, 
} 
0

Я уверен, что никакое соединение не производится, если вы не вызываете метод на интерфейсе. Тем более, что связь основана на HTTP.

В проекте, над которым я работал, на самом деле я создал метод NOP на сервере, который мог вызвать мой клиент. Я использовал это, чтобы определить, действительно ли предоставленная информация о подключении и учетные данные для входа действительны (с помощью блока try-catch).

Смежные вопросы