System.ServiceModel.Clientbase.Open() 的作用是什么?我从未使用过它,只是在一些代码中遇到过它。它可以抛出异常吗?如果没有调用 Close() 是否有问题?
如果您为 WCF 服务创建代理,则该代理实际上是 ClientBase
我的应用程序的示例:
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根据你的要求,我用谷歌搜索了一下,发现this http://msdn.microsoft.com/en-us/library/ms575279.aspx:
实现 ICommunicationObject.Open()
这导致this http://msdn.microsoft.com/en-us/library/ms195524.aspx:
通讯异常
ICommunicationObject 无法
已打开并已进入故障状态
状态。
超时异常
默认打开超时已过
在 ICommunicationObject 之前
能够进入Opened状态并且有
进入故障状态。
另外,根据经验和我在网上遇到的情况,不关闭您的客户可能会导致各种形式的奇怪现象发生,因此通常被认为是“一件坏事 http://www.catb.org/jargon/html/B/Bad-Thing.html".
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)