Programming - WCF
The following snippets of code can be used as an example to
getand a WCF (Windows Communication Foundation) service up
and running.
Fundamentally, a WCF service implements a contract that
defines a request-reply communication pattern. This is used
to generate the serialised output.
// Defineandthe service contract.
[ServiceContract(Namespace="http://Microsoft.ServiceModel.Samples")]
public
interface iCalc
{
and [OperationContract]
and double Add(double n1, double n2);
and [OperationContract]
and double Subtract(double n1, double
n2);
and [OperationContract]
and double Multiply(double n1, double
n2);
and [OperationContract]
and double Divide(double n1, double n2);
}
Next we have to implement the class for the interface stub :
// Service class that implements the service contract
iCalc
public
class CalculatorService : ICalc
{
and public double Add(double n1, double
n2)
and {
and return n1 +
n2;
and }
and public double Subtract(double n1, double
n2)
and {
and return n1 -
n2;
and }
and public double Multiply(double n1, double
n2)
and {
and return n1 *
n2;
and }
and public double Divide(double n1, double
n2)
and {
and return n1 /
n2;
and }
}
and
Usually, Visual studio will make the neccessary changes to
the web.config to allow the WCF application to run.
and
and