我有一个基于SoapHttpClientProtocol的WebService参考(.NET CF 3.5)。我的问题是-除了调用web方法之外,有没有一种方法可以确定是否建立了到WebService的连接?我是否可以随时检查底层连接是否已建立并获取其状态?
问候
发布于 2011-05-14 04:33:39
您可以在客户端上检查通信状态。
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,
}发布于 2011-05-14 23:54:00
我非常确定,除非在接口上调用方法,否则不会建立任何连接。特别是因为通信是基于HTTP的。
在我正在做的一个项目中,我实际上在服务器上创建了一个客户端可以调用的NOP方法。我使用它来确定提供的连接信息和登录凭据是否有效(通过使用try-catch块)。
https://stackoverflow.com/questions/3997711
复制相似问题