static void Main(string[] args) { try { IPHostEntry ips = Dns.GetHostEntry(Dns.GetHostName()); IPAddress _ipAddress = ips.AddressList[0]; string _ipAddressStr = TestWCF.Common.Host; // _ipAddress.ToString(); string endPointAddr = "net.tcp://" + _ipAddressStr + ":8000/" + TestWCF.Common.ServiceName; NetTcpBinding tcpBinding = new NetTcpBinding(); tcpBinding.TransactionFlow = false; tcpBinding.Security.Transport.ProtectionLevel = System.Net.Security.ProtectionLevel.EncryptAndSign; tcpBinding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Windows; tcpBinding.Security.Mode = SecurityMode.None; EndpointAddress endpointAddress = new EndpointAddress(endPointAddr); Console.WriteLine("Attempt to connect to: " + endPointAddr); TestWCF.IServiceContract proxy = ChannelFactory <TestWCF.IServiceContract> .CreateChannel(tcpBinding, endpointAddress); using (proxy as IDisposable) { Console.WriteLine("{0}", proxy.DoSmth(null)); TestWCF.DataContract dataContract = new TestWCF.DataContract { StringField = "StringField" }; Console.WriteLine("{0}", proxy.DoDmthWithClass(dataContract).StringField); } } catch (Exception eException) { Console.WriteLine("{1}{0}Message: \"{2}\"{3}{0}StackTrace:{0}{4}", Environment.NewLine, eException.GetType().FullName, eException.Message, eException.InnerException != null ? Environment.NewLine + "InnerException.Message: \"" + eException.InnerException.Message + "\"" : string.Empty, eException.StackTrace); } Console.ReadLine(); }
public string DoSmth(string inp) { return(_target.DoSmth(inp)); }
public void run() { string Msg; file.WriteLine(Msg = string.Format("{0}\tThread Id: {1} started...", DateTime.Now.ToString("HH:mm:ss.fffffff"), Thread.Name)); Console.WriteLine(Msg); try { IPHostEntry ips = Dns.GetHostEntry(Dns.GetHostName()); IPAddress _ipAddress = ips.AddressList[1]; string _ipAddressStr = TestWCF.Common.Host; // _ipAddress.ToString(); string endPointAddr = "net.tcp://" + _ipAddressStr + ":8000/" + TestWCF.Common.ServiceName; NetTcpBinding tcpBinding = new NetTcpBinding(); tcpBinding.TransactionFlow = false; tcpBinding.Security.Transport.ProtectionLevel = System.Net.Security.ProtectionLevel.EncryptAndSign; tcpBinding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Windows; tcpBinding.Security.Mode = SecurityMode.None; EndpointAddress endpointAddress = new EndpointAddress(endPointAddr); file.WriteLine(Msg = string.Format("{0}\tAttempt to connect to: {1} started...", DateTime.Now.ToString("HH:mm:ss.fffffff"), endPointAddr)); Console.WriteLine(Msg); TestWCF.IServiceContract proxy = ChannelFactory <TestWCF.IServiceContract> .CreateChannel(tcpBinding, endpointAddress); file.WriteLine(Msg = string.Format("{0}\tConnected", DateTime.Now.ToString("HH:mm:ss.fffffff"))); Console.WriteLine(Msg); using (proxy as IDisposable) { file.WriteLine(Msg = string.Format("{0}\tDoSmth({1}) started...", DateTime.Now.ToString("HH:mm:ss.fffffff"), Thread.Name)); Console.WriteLine(Msg); file.WriteLine(Msg = string.Format("{0}\tDoSmth({1}) finished (Result: \"{2}\")", DateTime.Now.ToString("HH:mm:ss.fffffff"), Thread.Name, proxy.DoSmth(Thread.Name))); Console.WriteLine(Msg); TestWCF.DataContract dataContract = new TestWCF.DataContract { StringField = Thread.Name }; file.WriteLine(Msg = string.Format("{0}\tDoSmthWithClass({1}) started...", DateTime.Now.ToString("HH:mm:ss.fffffff"), dataContract.StringField)); Console.WriteLine(Msg); file.WriteLine(Msg = string.Format("{0}\tDoSmthWithClass({1}) finished (Result: \"{2}\")", DateTime.Now.ToString("HH:mm:ss.fffffff"), dataContract.StringField, proxy.DoSmthWithClass(dataContract).StringField)); Console.WriteLine(Msg); } } catch (Exception eException) { file.WriteLine("{1}{0}{2}{0}Message: \"{3}\"{4}{0}StackTrace:{0}{5}", Environment.NewLine, DateTime.Now.ToString("HH:mm:ss.fffffff"), eException.GetType().FullName, eException.Message, eException.InnerException != null ? Environment.NewLine + "InnerException.Message: \"" + eException.InnerException.Message + "\"" : string.Empty, eException.StackTrace); } file.WriteLine(Msg = string.Format("{0}\tThread Id: {1} finished", DateTime.Now.ToString("HH:mm:ss.fffffff"), Thread.Name)); Console.WriteLine(Msg); }