What does ABC imply for WCF Service ? =>
ENDPOINT
Configuration of endpoint is done as below :
Contract: Attribute used in WCF is Service
Contract
E.g.:
--------------------------------------------------------------------------------------------------------------------------------------------------------
using System;
using System.ServiceModel;
namespace Microsoft.ServiceModel.Samples
{
    //
Define a service contract.
    [ServiceContract(Namespace = "http://Microsoft.ServiceModel.Samples")]
    public interface ICalculator
    {
        [OperationContract]
        double Add(double n1, double n2);
        [OperationContract]
        double Subtract(double n1, double n2);
        [OperationContract]
        double Multiply(double n1, double n2);
        [OperationContract]
        double Divide(double n1, double n2);
    }
    //
Step 1: Create service class that implements the service contract.
    public class CalculatorService : ICalculator
    {
         //
Step 2: Implement functionality for the service operations.
        public double Add(double n1, double n2)
        {
           
double
result = n1 + n2;
            Console.WriteLine("Received Add({0},{1})", n1, n2);
            //
Code added to write output to the console window.
            Console.WriteLine("Return: {0}",
result);
            return result;
        }
        public double Subtract(double n1, double n2)
        {
            double result = n1 - n2;
            Console.WriteLine("Received Subtract({0},{1})", n1, n2);
            Console.WriteLine("Return: {0}",
result);
            return result;
        }
        public double Multiply(double n1, double n2)
        {
            double result = n1 * n2;
            Console.WriteLine("Received Multiply({0},{1})", n1, n2);
            Console.WriteLine("Return: {0}",
result);
            return result;
        }
        public double Divide(double n1, double n2)
        {
            double result = n1 / n2;
            Console.WriteLine("Received Divide({0},{1})", n1, n2);
            Console.WriteLine("Return: {0}",
result);
            return result;
        }
    }
}
--------------------------------------------------------------------------------------------------------------------------------------------------------  
Where and How?
Following is
configuration required for WCF service, Configuration we will see in depth in
later articles,
Note following tabgs,
Services
->Service[attribute->Name]
->Enpoint[Attribute-> address, binding, contract]
Configuration is enough
for understanding the explanation and figure mentioned earlier.
xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="CalculatorServiceBehavior">
          <serviceMetadata httpGetEnabled="True"/>
        behavior>
      serviceBehaviors>
    behaviors>
    <services>
      <service name="Microsoft.ServiceModel.Samples.CalculatorService"
               behaviorConfiguration="CalculatorServiceBehavior">
        <endpoint address="http://localhost:8080/calcservice" binding="basicHttpBinding" contract="ICalculator"/>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      service>
    services>
  system.serviceModel>
configuration>
EndPoints:
All communication with a
Windows Communication Foundation (WCF) service occurs through the endpoints of
the service. Endpoints provide clients access to the functionality offered by a
WCF service.
Each endpoint consists of four properties:
·        
An address that
indicates where the endpoint can be found. 
·        
A binding that specifies
how a client can communicate with the endpoint. 
·        
A contract that
identifies the operations available. 
·        
A set of behaviors (OperationContract) that specify local implementation details of
the endpoint. 
Client Communication:
- · Consume Services via Channels based on Endpoints (Binding)
- · Client retrieves Endpoint using Metadata information (WSDL)
- · Regarding WSDL and Metadata we will see in coming articles.

Channels is whole huge
topic can’t be covered in scope of this article though.
Channels Abstract:
The Windows Communication
Foundation (WCF) channel stack is a layered communication stack with one or
more channels that process messages. WCF binding is composed of binding elements and each binding element
is corresponding to a specific channel in Channel Stack.
Application-to-application communication can have many
aspects. Perhaps a SOAP envelope needs to be created, for example, wrapping
whatever information is being sent. Maybe one or more of the WS-* technologies
should be used, such as WS-ReliableMessaging or WS-Security. Perhaps the
information to be sent should be represented using JavaScript Object Notation
(JSON). Or maybe none of these things are required: Just sending plain XML
might be sufficient. And however a message is structured, it must eventually be
sent to its destination using HTTP, TCP, Microsoft Messaging Queuing (MSMQ), or
something else.
 WCF's Design for Diversity was the reason for which 2 big ideas were introduced “Binding and Channels” to WCF. By specifying a particular binding, a
WCF client or service implicitly creates a channel stack that implements a particular set of communication behaviors. So,
a single channel in channel stack is unit of binding.
Next we will see ,
- ServiceContract
- OperatioCOntract
- DataContract
- MessageContract



 
0 comments:
Post a Comment