Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does System.ServiceModel.Clientbase.Open() do?

Tags:

c#

wcf

What does System.ServiceModel.Clientbase.Open() do? I've never used it but just came across it in some code. Can it throw exceptions? If Close() is not called is it a problem?

like image 691
xr280xr Avatar asked Mar 12 '11 01:03

xr280xr


1 Answers

If you create a proxy for a WCF service the proxy is effectively ClientBase

Example from my app:

public class DataClient : ClientBase<Classes.IDataService>, Classes.IDataService
{
    public DataClient(string connectToHost)
        : base(new NetTcpBinding(SecurityMode.Transport)
            {
                PortSharingEnabled = true,
                Security = new NetTcpSecurity()
                {
                    Transport = new TcpTransportSecurity()
                    {
                        ClientCredentialType = TcpClientCredentialType.Windows
                    }
                }
            },
            new EndpointAddress(string.Format("net.tcp://{0}:5555/MyService",connectToHost)))
    { }

    #region IDataService Members

    public Classes.Folder GetFolder(string entryID)
    {
        return Channel.GetFolder(entryID);
    }

    public Classes.IItem GetItem(string entryID)
    {
        return Channel.GetItem(entryID);
    }

    #endregion
}

EDIT Per your request I googled a bit and found this:

Implements ICommunicationObject.Open()

This led to this:

CommunicationException

The ICommunicationObject was unable to be opened and has entered the Faulted state.

TimeoutException

The default open timeout elapsed before the ICommunicationObject was able to enter the Opened state and has entered the Faulted state.

Also, per experience and what I've come across on the 'net not closing your clients can cause various forms of strangeness to occur and is thus generally considered "A Bad Thing".

like image 182
Vincent Vancalbergh Avatar answered Oct 11 '22 06:10

Vincent Vancalbergh