- wcfdiag_src.zip
- Scratch
- WCFDiagArticle
- Interfaces
- Proxies
- WCFClient
- WCFService
|
using System;
using System.Collections.Generic;
using System.Text;
using System.ServiceModel;
using System.Diagnostics;
using System.Configuration;
namespace CheckPointe
{
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Multiple)]
public class WCFService : IWCFService
{
/// <summary>
/// Returns the result of the requested operation
/// </summary>
/// <param name="op"></param>
/// <param name="value1"></param>
/// <param name="value2"></param>
/// <returns></returns>
public OperationResult DoOperation(OperationType op, int value1, int value2)
{
OperationResult or = new OperationResult();
try
{
switch (op)
{
case OperationType.Add:
or.Value = value1 + value2;
break;
case OperationType.Sub:
or.Value = value1 - value2;
break;
case OperationType.Mul:
or.Value = value1 * value2;
break;
case OperationType.Div: //exception will catch div by zero
or.Value = value1 / value2;
break;
}
or.Result = ResultCode.Success;
}
catch (System.Exception ex)
{
Trace.WriteLine(ex.Message);
or.Result = ResultCode.Fail;
}
return or;
}
static void Main(string[] args)
{
NetTcpBinding tcpBinding = new NetTcpBinding();
NetNamedPipeBinding pipeBinding = new NetNamedPipeBinding();
Uri tcpBaseAddress;
Uri pipeBaseAddress;
ServiceHost host = null;
try
{
//We'll support two transports, one local and one remote
tcpBaseAddress = new Uri(ConfigurationManager.AppSettings["baseTcpWCFService"]);
pipeBaseAddress = new Uri(ConfigurationManager.AppSettings["basePipeWCFService"]);
host = new ServiceHost(typeof(CheckPointe.WCFService), tcpBaseAddress, pipeBaseAddress);
host.AddServiceEndpoint(typeof(CheckPointe.IWCFService), tcpBinding, tcpBaseAddress);
host.AddServiceEndpoint(typeof(CheckPointe.IWCFService), pipeBinding, pipeBaseAddress);
host.Open();
// The service can now be accessed.
Console.WriteLine("The service is ready.");
Console.WriteLine("Press <ENTER> to terminate service.");
Console.WriteLine();
Console.ReadLine();
}
catch (System.Exception ex)
{
Trace.WriteLine(ex.Message);
}
if (host != null)
host.Close(); //Release host
}
}
}
namespace WCFService
{
class Program
{
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.