WCF4StepByStepChapter1, 2 Note

Source: Internet
Author: User
HowDoesaWCFServiceWork? Ahostapplicationmustperformseveraltasks, whichinclude: | Startingandstoppingtheservice | Listeningforrequestsfromaclientapplicationanddirectingthemtotheservice | Sendinganyresponsesfr

How Does a WCF Service Work? A host application must perform several tasks, whichinclude: | Starting and stopping the service | Listening for requests from a client application anddirecting them to the service | Sending any responses fr

How Does a WCF Service Work?

A host application must perform several tasks, whichinclude:

| Starting and stopping the service

| Listening for requests from a client application anddirecting them to the service

| Sending any responses from the service back to the clientapplications

Service Endpoints

-The address of the service

-The binding supported by the service

-Thetransport protocol

-Ifyou are using IIS to host the service, you shoshould specify

The HTTP or HTTPS transport protocol. WCF also has built-insupport for the TCP

Protocol, named-pipes, and message queues.

-The encoding format of messages

-In‑cases, request and response messages will be transmitted in XML format, encoded as ordinary text. However, in some

Cases you might need to transmit data using a binaryencoding, especially if you are transmitting images or handling streams

-The security requirements of the service

-Youcan implement security at the transport level and at the message level

-The transactional requirements of the service

-The reliability of communications with the service

-Networksare notoriously unreliable and can fail at any time.

-The contract implemented by the service.


Processing a Client Request

The WCF runtime environment for a client application and a service provides acollection of channel objects that can perform this processing for you.

A channel is responsible for handling one aspect of message processing, as specified by the bindings of a service

The WCF runtime composes channels into a channel stack. all messages passing between the client and the service go through each channel in the channel stack. each channel in the channel stack transforms the message in some way, and the output from one channel is passed as input to the next

The host application must ensure that messages being sent between the client and service conform to the security, reliability, and transactional requirements of the binding being used. when you start a service running, theWCF runtime uses the endpoint information specified as part of the service configuration andcreates alistener objectfor each address specified for the service. when an incoming request is wrongly ed, theWCF runtimeconstructs a channel stack by using the binding information specified for the address and routes the incoming data from the client through the stack. if a message successfully traverses all the channels in
Channel stack, the transformed request is passed to an instance of the service for processing.

WCF service must be able to handle requests from multiple client applications simultaneously. To do this, the WCF runtime can createmultiple concurrent
Instances of a service. The WCF runtime creates an InstanceContext object to control the interaction between the channel stack and a service instance


WAS (Windows Process Activation Service)

The Windows Process Activation Service (WAS) extends the functionality of IIS by removing the dependency on the HTTP protocol. using WAS, you can host services that make use of other protocols, such as TCP, named pipes, and Microsoft Message Queues.


Windows Server AppFabric

If you are hosting WCF services by using IIS or WAS in a production environment, you might want to consider implementing Windows Server AppFabric.

Windows Server AppFabric is a set of extensions to the Windows operating system aimed at making it easier for developers to build faster, scalable, and more-easily managed services. appFabric provides adistributed in-memory caching service and replication technology that helps developers improve the speed and availability of ASP. NET Web applications and WCF services. appFabric also includes hosting features that can simplify the deployment, monitoring, and management of services by making use of familiar tools such as PowerShell, Internet Information Services Manager, and Microsoft System Center.


Hosting a Service in a User Application
If you are building your own host application rather than using IIS or WAS, you can achieve most of these tasks by using theServiceHostclass, available in
System. ServiceModel namespace. Opening a ServiceHost object causes the WCF runtime to examine the binding configuration for each endpoint of the service and start listening on each endpoint address.

productsServiceHost.Open();


Host service in User Application vs. IIS or WAS
Previusly, when you hosted the service in IIS and WAS, you did not need to provide an endpoint definition in the configuration file. this was because the WCF runtime cocould deduce default values for each of the items that constituted the endpoint; the address was determined by concatenating the name of. svc file to the virtual folder holding the service, the binding was assumed to be basic HTTP, and the service defined only a single service contract. when you build a custom host application, these assumptions are no longer valid, so you must specify them in the configuration file.

IIS or WAS



Deploying a WCF Service in IIS Without an. svc File

The. svc file is a special content file that IIS uses to recognize a WCF service. It provides the information that the hosting environment in IIS uses to activate the WCF run time and start the service.

WCF 4.0 provides a feature called Configuration-Based Activation, with which you can combine the information normally encoded in the. svc file directly into the Web. config
File for a WCF service hosted by IIS.


     
        
           
              
               
               
               
             
          
       
      
        
                   
         
    
 


Understanding Endpoints and Bindings

An endpoint specifies the point of contact for a service; it provides the address that the service listens to, the binding that the client must use to connect to the service,
And the contract that defines the functionality exposed by the service. This is the information that a client application must specify to successfully connect to the service.

A binding element corresponds to a channel. Remember that when a host opens a service, the WCF runtime uses each binding element in the binding
Configuration to create the channel stack. A client also creates a channel stackwhen it connects to the serviceby opening a proxy object. to ensure that a client application can communicate successfully with a service, it shocould use a binding configuration that provides binding elements that match those implemented by the service.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.