SoapHttpClientProtocol / HttpWebClientProtocol连接状态

时间:2010-10-22 14:19:21

标签: c# .net web-services http soap

我有一个基于SoapHttpClientProtocol的WebService引用(.NET CF 3.5)。我的问题是 - 除了调用Web方法之外,有没有办法确定是否建立了与WebService的连接?我可以随时检查基础连接是否已建立并获得其状态?

此致

2 个答案:

答案 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,
}

答案 1 :(得分:0)

除非你在界面上调用方法,否则我很确定没有连接。特别是因为通信是基于HTTP的。

在我正在开发的项目中,我实际上在客户端可以调用的服务器上创建了一个NOP方法。我用它来确定提供的连接信息和登录凭证是否有效(通过使用try-catch块)。