我有一个基于SoapHttpClientProtocol的WebService引用(.NET CF 3.5)。我的问题是 - 有没有方法可以确定是否建立了与WebService的连接,而不是调用Web方法?我可以随时检查底层连接是否已建立并获得其状态?SoapHttpClientProtocol/HttpWebClientProtocol连接状态
Regards
我有一个基于SoapHttpClientProtocol的WebService引用(.NET CF 3.5)。我的问题是 - 有没有方法可以确定是否建立了与WebService的连接,而不是调用Web方法?我可以随时检查底层连接是否已建立并获得其状态?SoapHttpClientProtocol/HttpWebClientProtocol连接状态
Regards
您可以检查客户端的通信状态。
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,
}
我很确定没有连接,除非你在接口上调用方法。特别是因为通信是基于HTTP的。
在我正在开发的一个项目中,我实际上在客户端可以调用的服务器上创建了一个NOP方法。我用它来确定提供的连接信息和登录凭证是否有效(通过使用try-catch块)。
你需要通过代码做出这个决定吗? – 2011-05-13 14:40:36