// server
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ServiceModel;
using System.ServiceModel.Channels;
public class Tset
{
public static void Main ()
{
ServiceHost host = new ServiceHost (typeof (Foo));
var b = new CustomBinding (
new BinaryMessageEncodingBindingElement (),
new TcpTransportBindingElement ());
host.AddServiceEndpoint ("IFoo", b, "net.tcp://localhost:8080");
host.Open ();
Console.WriteLine ("Hit [CR] key to close ...");
Console.ReadLine ();
host.Close ();
}
}
[ServiceContract (CallbackContract = typeof (IFoo))]
public interface IFoo
{
[OperationContract]
string Echo (string msg);
}
class Foo : IFoo
{
public string Echo (string msg)
{
var c = OperationContext.Current.Channel;
Console.WriteLine (c.GetType ().GetInterfaces ().Length);
Console.WriteLine (c is IContextChannel);
return msg + msg;
}
}
// client
using System;
using System.ServiceModel;
public class Tset
{
public static void Main ()
{
var binding = new NetTcpBinding ();
binding.Security.Mode = SecurityMode.None;
IFoo proxy = new ChannelFactory<IFoo> (
binding, "net.tcp://localhost:8080/")
.CreateChannel ();
Console.WriteLine (proxy.Echo ("TEST FOR ECHO"));
}
}
[ServiceContract]
public interface IFoo
{
[OperationContract]
string Echo (string msg);
}
/* results
$ ./server.exe
Hit [CR] key to close ... // run client from another terminal
0
True
*/