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

Home | Privacy Policy | Site Map | Links | Company | Contact Us | Arena           

We provide cutting edge software development, consultancy and web design services            

There are currently 529 user(s) with 33580 hits.