Sunday, 18 May 2014

What is End piont in WCF with Example.

 End point: 
1. Where is Address-->http/local host
2. How to Binding -->how u communicate-->protocol
3. What is Contract--> it tell to client what i am?
WCF Service is a program that displays a set of evaluation criteria. Each endpoint is the gateway to communicate with the world.
All communication is through the WCF is endpoint. Endpoint consists of three elements.


Address :-Basically URL, which determines the service is hosted WCF. Customers will use this link to connect to the service.  
For example
http://localhost:8090/MyService/SimpleCalculator.svc 

Binding :-Describes how binding the client will communicate with the service. There are different protocols available for the client to connect to the WCF. It can remind you type protocol based on your needs.
Link has many features, including the following:

  •   Transport -Defines the base protocol to be used like HTTP, Named Pipes, TCP, and MSMQ are some type of protocols.  
  •  Encoding (Optional) - Three types of encoding are available-Text, Binary, or Message Transmission Optimization Mechanism (MTOM). MTOM is an interoperable message format that allows the effective transmission of attachments or large messages (greater than 64K). 
  •    Protocol(Optional) - Defines information to be used in the binding such as Security, transaction or reliable messaging capability
 The following table gives some list of protocols supported by WCF binding.


Binding
Description
BasicHttpBinding
Basic Web service communication. No security by default
WSHttpBinding
Web services with WS-* support. Supports transactions
WSDualHttpBinding
Web services with duplex contract and transaction support
WSFederationHttpBinding
Web services with federated security. Supports transactions
MsmqIntegrationBinding
Communication directly with MSMQ applications. Supports transactions
NetMsmqBinding
Communication between WCF applications by using queuing. Supports transactions
NetNamedPipeBinding
Communication between WCF applications on same computer. Supports duplex contracts and transactions
NetPeerTcpBinding
Communication between computers across peer-to-peer services. Supports duplex contracts
NetTcpBinding
Communication between WCF applications across computers. Supports duplex contracts and transactions
 Contract:-Collection process determines endpoint connection with the outside world. Typically, the name of the interface in the contract, so the client is aware of the operations are exposed to the client. Each transaction is a simple form of exchange, as a way, duplex and request / response.
Below illustrate the endpoint Features




Example:
Eventually will be mentioned in the web.config file on the service that has been created.



<system.serviceModel>
<services>
      <service name="MathService"
        behaviorConfiguration="MathServiceBehavior">
       <endpoint
         address="http://localhost:8090/MyService/MathService.svc" contract="IMathService"
          binding="wsHttpBinding"/> 
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="MathServiceBehavior">
          <serviceMetadata httpGetEnabled="True"/>
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
Read More...

Wednesday, 14 May 2014

Introduction to WCF.

WCF( Windows Communication Foundation ):- Windows Communication Foundation (code named Indigo) is a programming platform and operating system to build, configure and deploy distributed network services. This is the latest technology services; interoperability are the basic characteristics of the Working Capital Fund. Is a unified programming model provided by the Net Framework 3.0. WCF is a combined features of Web Service, Remoting, and MSMQ COM +. Provides Working Capital Fund a common platform for all. NET communications.




What is EndPoint ?

IIS 5/6 Hosting

The main advantage of hosting service is that IIS will automatically start when the host process is put the client's request first. IIS uses features such as recycling process, and the closure of inactivity, health monitoring and activation process messages list. The main disadvantage of using IIS is that the HTTP protocol support only.
That like some hands, to create a set of service and IIS.


Step1:- Start program Visual Studio 2008, and then click File> New> Web site. Select 'Service WCF "and the site as HTTP. Will host this service directly into IIS, and then click OK.

 
Step2:- I created HelloWorld service appears to accept as input a name and back with 'hello' and the name. Are then displayed interface and service implementation.



IMyService.cs
[ServiceContract]
public interface IMyService
{
    [OperationContract]
    string HelloWorld(string name);   

}
MyService.cs
public class MyService : IMyService
{

    #region IMyService Members

    public string HelloWorld(string name)
    {
        return "Hello " + name;
    }

    #endregion
}
  Step3:-Service file (. SVC) contains the name of the service and the code behind the file name. It uses this file to identify the service.



MyService.svc
<%@ ServiceHost Language="C#" Debug="true"
Service="MyService" CodeBehind="~/App_Code/MyService.cs" %>
  Step4:-According to the settings in the server configuration file. I'm here to have a single endpoint that is configured for recovery 'wsHttpBinding', may also have multiple endpoint with differnet binding. As we will host in IIS. We only use HTTP link. Let's get to know more at the end, and its configuration in a later tutorial. Web.config file



<system.serviceModel>
  <services>
   <service behaviorConfiguration="ServiceBehavior" name="MyService">
        <endpoint address="http://localhost/IISHostedService/MyService.svc"
        binding="wsHttpBinding" contract="IMyService">
        <identity>
        <dns value="localhost"/>
        </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
   </service>
 </services>
 <behaviors>
  <serviceBehaviors>
    <behavior name="ServiceBehavior">
        <!-- To avoid disclosing metadata information,
        set the value below to false and remove the
        metadata endpoint above before deployment -->
      <serviceMetadata httpGetEnabled="true"/>
        <!-- To receive exception details in faults for
        debugging purposes, set the value below to true. 
        Set to false before deployment to avoid disclosing exception information -->
        <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
   </serviceBehaviors>
  </behaviors>
</system.serviceModel>
  
Note: It is necessary to mention the name of the service, along with references to addresses in the configuration file. Snapshot IIS


   
 This screen will appear when we run the application.

 
Step5:Now we get a successful service in IIS. Then we need to consume this service in the client application. Before creating a client application, we need to create a proxy for this service. This agent is used by the client application to interact with the service. To create a proxy, run Visual Studio 2008 command prompt. Using the service tool that can create a proxy class and configuration information.



svcutil  http://localhost/IISHostedService/MyService.svc
















 After executing this command we will find two file generated in the default location
  •    MyService.cs - Proxy class for the WCF service
  •    output.config - Configuration information about the service
 Step6:Now let's start creating the console application with Visual Studio 2008 (client application).
 
Step7:-Add the reference 'System.ServiceModel'; this is the core dll for WCF.




Step8:- Create the object for the proxy class and call the HelloWorld method.


static void Main(string[] args)
        {
            //Creating Proxy for the MyService
             MyServiceClient client = new MyServiceClient();
             Console.WriteLine("Client calling the service...");
             Console.WriteLine(client.HelloWorld("Ram"));
             Console.Read();

        }

 Step9:-If we run the application we will find the output as shown below.

Read More...