日期:2014-05-17 浏览次数:20898 次
internal static ServiceHost myServiceHost = null;
public bool Open_service(string ip)
{
if (myServiceHost != null)
{
Stop_service();
}
if (ip != "")
{
Trace.Listeners.Clear();
Trace.Listeners.Add(new ConsoleTraceListener());
NetTcpBinding myBinding = new NetTcpBinding();
// WSHttpBinding myBinding = new WSHttpBinding();
myBinding.Security.Mode = SecurityMode.None;
myBinding.MaxReceivedMessageSize = 2147483647;
myBinding.TransferMode = TransferMode.Buffered;
myBinding.ReaderQuotas = new System.Xml.XmlDictionaryReaderQuotas();
myBinding.ReaderQuotas.MaxArrayLength = int.MaxValue;
myBinding.ReaderQuotas.MaxStringContentLength = int.MaxValue;
Uri baseAddress = new Uri("net.tcp://" + ip + ":8057/WCFService/");
myServiceHost = new ServiceHost(typeof(Service1), baseAddress);
ServiceEndpoint myServiceEndpoint = myServiceHost.AddServiceEndpoint
(typeof(IService1), myBinding, "GetIdentity");
try
{
myServiceHost.Open();