我只知道WCF单工,控制台承载WCF服务时的代码:
class Program
{
static void Main(string[] args)
{
Uri baseAddress = new Uri("http://localhost:8000/MyService");
ServiceHost selfHost = new ServiceHost(typeof(MyService), baseAddress);
try
{
selfHost.AddServiceEndpoint(typeof(IService), new WSHttpBinding(), "MyService");
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
selfHost.Description.Behaviors.Add(smb);
selfHost.Open();
Console.WriteLine("服务已准备就绪");
Console.WriteLine("按下回车键以终止服务");
Console.WriteLine();
Console.ReadLine();
selfHost.Close();
}
catch (CommunicationException ce)
{
Console.WriteLine("异常:{0}", ce.Message);
Console.ReadKey();
selfHost.Abort();
}
}
}
那如果是WCF双工,并且要求使用NetTcpBinding绑定,控制台承载的代码怎么写的呢?试了好几次都没成功
------解决思路----------------------
serviceHost = new ServiceHost(typeof(WcfService));
NetTcpBinding binding = new NetTcpBinding();
//Updated: to enable file transefer of 64 MB (67108864)
binding.Security.Mode = SecurityMode.None;
binding.MaxBufferSize = 104857600;
binding.MaxReceivedMessageSize = 104857600;
binding.MaxBufferPoolSize = 104857600;
binding.ReceiveTimeout = new TimeSpan(10, 0, 0);
binding.SendTimeout = new TimeSpan(10, 0, 0);
binding.ReaderQuotas.MaxArrayLength = 104857600;
binding.ReaderQuotas.MaxBytesPerRead = 104857600;
binding.MaxConnections = 65535;
binding.TransferMode = TransferMode.Buffered;
serviceHost.AddServiceEndpoint(typeof(IService), binding, string.Format("net.tcp://localhost:8000/service", Port));
//To maxmize MaxConnections you have to assign another port for mex endpoint
//and configure ServiceThrottling as well
ServiceThrottlingBehavior throttle = serviceHost.Description.Behaviors.Find<ServiceThrottlingBehavior>();
if (throttle == null)
{
throttle = new ServiceThrottlingBehavior();
throttle.MaxConcurrentCalls = 65535;
throttle.MaxConcurrentSessions = 65535;
throttle.MaxConcurrentInstances = 500;
serviceHost.Description.Behaviors.Add(throttle);
}
------解决思路----------------------
主程序创建service,然后start
------解决思路----------------------
http://www.cnblogs.com/yank/p/3668369.html
------解决思路----------------------
http://www.cnblogs.com/artech/archive/2007/03/02/661969.html
这个,还有结合我上面的代码,

------解决思路----------------------
serviceHost.AddServiceEndpoint(typeof(IService), binding, “net.tcp://localhost:8000/service”) 这样你看懂了吧,
你说的Open自己在代码最后Open一下呗
------解决思路----------------------
net.tcp://localhost:8000/service<----看清楚了,是service,不是myservice这个要自己调整
------解决思路----------------------
http://blog.csdn.net/jiankunking/article/details/46967553