gpt4 book ai didi

c# - System.ServiceModel.Clientbase.Open() 是做什么的?

转载 作者:太空狗 更新时间:2023-10-29 23:26:27 27 4
gpt4 key购买 nike

System.ServiceModel.Clientbase.Open() 有什么作用?我从未使用过它,只是在一些代码中遇到过它。它能抛出异常吗?如果不调用 Close() 是否有问题?

最佳答案

如果您为 WCF 服务创建代理,代理实际上是 ClientBase

来 self 的应用的示例:

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
}

编辑根据你的要求,我用谷歌搜索了一下,发现 this :

Implements ICommunicationObject.Open()

这导致了 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.

此外,根据经验和我在网上遇到的情况,如果不关闭您的客户端,可能会导致出现各种形式的奇怪情况,因此通常被认为是“A Bad Thing”。

关于c# - System.ServiceModel.Clientbase.Open() 是做什么的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5280072/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com