I have a WebService reference (.NET CF 3.5) based on SoapHttpClientProtocol. My question is - is there a way to determine whether a connection to WebService is established othe开发者_开发问答r than calling a web method? Can I check at any time that the underlying connection is established and get its status?
Regards
You can check the communication state on the client.
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,
}
I'm pretty sure no connection is made unless you call a method on the interface. Especially since the communication is HTTP-based.
In a project I was working on, I actually created a NOP method on the server that my client could call. I used that to determine if the supplied connection information and login credentials are valid (by using a try-catch block).
精彩评论