Intranet Unsecured Client and Service

The following illustration depicts a simple Windows Communication Foundation (WCF) service developed to provide information on a secure private network to a WCF application. Security is not required because the data is of low importance, the network is expected to be inherently secure, or security is provided by a layer below the WCF infrastructure.

Code

Uri tcpUri = new Uri("net.tcp://localhost:8008/Calculator");
// Create the ServiceHost.
ServiceHost sh = new ServiceHost(typeof(Calculator), tcpUri);
// Create a binding that uses TCP and set the security mode to none.
NetTcpBinding b = new NetTcpBinding();
b.Security.Mode = SecurityMode.None;
// Add an endpoint to the service.
sh.AddServiceEndpoint(typeof(ICalculator), b, "");
// Open the service and wait for calls.
sh.Open();
string listenUri = sh.Description.Endpoints[0].ListenUri.AbsoluteUri;
Console.WriteLine("Listening on: {0}", listenUri);
Console.Write("Press Enter to end the service");
Console.ReadLine();
// Close the service when a key is pressed.

Code

// Create an instance of the NetTcpBinding and set the// security mode to none.
NetTcpBinding myBinding = new NetTcpBinding();
myBinding.Security.Mode = SecurityMode.None;
// Create the address string, or get it from configuration.string tcpUri = "net.tcp://machineName:8008/Calculator";
// Create an endpoint address with the address.
EndpointAddress myEndpointAddress = new EndpointAddress(tcpUri);
// Create an instance of the WCF client. The client// code was generated using the Svcutil.exe tool.
CalculatorClient cc = new CalculatorClient(myBinding, myEndpointAddress);
try
{
cc.Open();