【发布时间】:2009-12-18 19:51:17
【问题描述】:
我的所有连接都是通过我的代码设置的,而不是使用我的配置文件。如何在从代码构建的连接上设置 WCF 跟踪。正如here 解释的那样,我尝试将跟踪添加到配置文件中,但它不会产生任何日志。
我需要知道如何从配置文件中使其工作以在代码中设置连接,或者如果有人有任何信息,如何在代码中手动配置它。谢谢!
编辑:添加更多信息:
应用程序是一个 C# 控制台应用程序,我的绑定声明为:
private Binding getBinding()
{
NetTcpBinding tcp = new NetTcpBinding();
tcp.ReaderQuotas.MaxArrayLength = 65535;
tcp.TransferMode = TransferMode.Streamed;
tcp.ReaderQuotas.MaxArrayLength = int.MaxValue;
tcp.ReaderQuotas.MaxDepth = int.MaxValue;
tcp.ReaderQuotas.MaxStringContentLength = int.MaxValue;
tcp.ReaderQuotas.MaxBytesPerRead = int.MaxValue;
tcp.ReaderQuotas.MaxNameTableCharCount = int.MaxValue;
tcp.MaxReceivedMessageSize = int.MaxValue;
return tcp;
}
然后我使用通用函数向我的应用添加服务:
private List<ServiceHost> m_Hosts = new List<ServiceHost>();
private static List<string> m_Services = new List<string>();
public void AddHost<T1, T2>(string uri)
where T1 : class
where T2 : class
{
m_Services.Add("net.tcp://<ipaddress>:<port>/" + uri);
m_Hosts.Add(new ServiceHost(typeof(T1)));
m_Hosts[m_Hosts.Count - 1].AddServiceEndpoint(typeof(T2), getBinding(), m_Services[m_Services.Count - 1]);
}
显然还有一些代码可以使这一切正常工作,但这应该提供任何相关部分。
【问题讨论】: