Dotnet3.5_WCF
-
Upload
rajanikantsingh -
Category
Documents
-
view
221 -
download
0
Transcript of Dotnet3.5_WCF
![Page 1: Dotnet3.5_WCF](https://reader030.fdocuments.in/reader030/viewer/2022021316/577cc8cd1a28aba711a33e14/html5/thumbnails/1.jpg)
8/12/2019 Dotnet3.5_WCF
http://slidepdf.com/reader/full/dotnet35wcf 1/33
Confidential ©2009 Syntel, Inc.
WCF
![Page 2: Dotnet3.5_WCF](https://reader030.fdocuments.in/reader030/viewer/2022021316/577cc8cd1a28aba711a33e14/html5/thumbnails/2.jpg)
8/12/2019 Dotnet3.5_WCF
http://slidepdf.com/reader/full/dotnet35wcf 2/33
Confidential ©2009 Syntel, Inc.
.NET 3.0
![Page 3: Dotnet3.5_WCF](https://reader030.fdocuments.in/reader030/viewer/2022021316/577cc8cd1a28aba711a33e14/html5/thumbnails/3.jpg)
8/12/2019 Dotnet3.5_WCF
http://slidepdf.com/reader/full/dotnet35wcf 3/33
Confidential ©2009 Syntel, Inc.
Additive versions of the .NET Framework
![Page 4: Dotnet3.5_WCF](https://reader030.fdocuments.in/reader030/viewer/2022021316/577cc8cd1a28aba711a33e14/html5/thumbnails/4.jpg)
8/12/2019 Dotnet3.5_WCF
http://slidepdf.com/reader/full/dotnet35wcf 4/33
Confidential ©2009 Syntel, Inc.
What Is WCF?
WCF is the Microsoft next generation technology for
developing distributed applications
WCF has been built to facilitate the development of service-
oriented applications
The communication between loosely coupled clients and
services is based on a model that uses schemas and
contracts, rather than classes and types
![Page 5: Dotnet3.5_WCF](https://reader030.fdocuments.in/reader030/viewer/2022021316/577cc8cd1a28aba711a33e14/html5/thumbnails/5.jpg)
8/12/2019 Dotnet3.5_WCF
http://slidepdf.com/reader/full/dotnet35wcf 5/33
Confidential ©2009 Syntel, Inc.
Three Major Goals
What does WCF Solves?
![Page 6: Dotnet3.5_WCF](https://reader030.fdocuments.in/reader030/viewer/2022021316/577cc8cd1a28aba711a33e14/html5/thumbnails/6.jpg)
8/12/2019 Dotnet3.5_WCF
http://slidepdf.com/reader/full/dotnet35wcf 6/33
Confidential ©2009 Syntel, Inc.
Why Handle Unification?
Current distributed technologies are based on different programming models
For example, if you are building an application that happens to communicateover HTTP, you will be required to change your programming model if you want
to switch to using TCP
If you are used to building XML web services today, you don’t have the ability to
support and flow transactions with message queuing enabled without changing
your programming model.
It avoids confusion by taking all the capabilities of the existing distributed
systems’ technology stacks and enables you to use one clean and simple API.
![Page 7: Dotnet3.5_WCF](https://reader030.fdocuments.in/reader030/viewer/2022021316/577cc8cd1a28aba711a33e14/html5/thumbnails/7.jpg)
8/12/2019 Dotnet3.5_WCF
http://slidepdf.com/reader/full/dotnet35wcf 7/33
Confidential ©2009 Syntel, Inc.
![Page 8: Dotnet3.5_WCF](https://reader030.fdocuments.in/reader030/viewer/2022021316/577cc8cd1a28aba711a33e14/html5/thumbnails/8.jpg)
8/12/2019 Dotnet3.5_WCF
http://slidepdf.com/reader/full/dotnet35wcf 8/33
Confidential ©2009 Syntel, Inc.
WCF As a Service-Oriented Development Tool
Service orientation is not a technology but instead is a
design concept
Service orientation uses the best practices for building
today’s distributed applications
Although existing distributed technologies can offer the
groundwork for interoperability and integration, a newplatform was required—a new infrastructure that makes it
much easier to build these distributed technologies
![Page 9: Dotnet3.5_WCF](https://reader030.fdocuments.in/reader030/viewer/2022021316/577cc8cd1a28aba711a33e14/html5/thumbnails/9.jpg)
8/12/2019 Dotnet3.5_WCF
http://slidepdf.com/reader/full/dotnet35wcf 9/33
Confidential ©2009 Syntel, Inc.
WCF As a Service-Oriented Development Tool
One of the challenges in developing WCF is shifting
developers’ mind-sets away from thinking about buildingdistributed systems in terms of objects and components and
starting to think about building distributed systems as
services.
![Page 10: Dotnet3.5_WCF](https://reader030.fdocuments.in/reader030/viewer/2022021316/577cc8cd1a28aba711a33e14/html5/thumbnails/10.jpg)
8/12/2019 Dotnet3.5_WCF
http://slidepdf.com/reader/full/dotnet35wcf 10/33Confidential ©2009 Syntel, Inc.
WCF Programming Model
SO or OO?
When developing WCF services, which do you use? Do you use a
service-oriented approach or an object-oriented approach to
developing a WCF solution?
The answer is, both.
Simply put, object-oriented programming is used to developapplications, and service-oriented programming is used to connect
those applications.
Think ―object-orientation = tightly coupled, and service-
orientation = loosely coupled.‖
![Page 11: Dotnet3.5_WCF](https://reader030.fdocuments.in/reader030/viewer/2022021316/577cc8cd1a28aba711a33e14/html5/thumbnails/11.jpg)
8/12/2019 Dotnet3.5_WCF
http://slidepdf.com/reader/full/dotnet35wcf 11/33Confidential ©2009 Syntel, Inc.
WCF Service from the outside
![Page 12: Dotnet3.5_WCF](https://reader030.fdocuments.in/reader030/viewer/2022021316/577cc8cd1a28aba711a33e14/html5/thumbnails/12.jpg)
8/12/2019 Dotnet3.5_WCF
http://slidepdf.com/reader/full/dotnet35wcf 12/33Confidential ©2009 Syntel, Inc.
WCF Service from the inside
![Page 13: Dotnet3.5_WCF](https://reader030.fdocuments.in/reader030/viewer/2022021316/577cc8cd1a28aba711a33e14/html5/thumbnails/13.jpg)
8/12/2019 Dotnet3.5_WCF
http://slidepdf.com/reader/full/dotnet35wcf 13/33Confidential ©2009 Syntel, Inc.
WCF Contracts
WCF contracts define the behavior of WCF services
They are created in code by service developers, and are exposed toclients in the service metadata
The five types of contracts:
Service Contracts
Operation Contracts
Data Contracts
Message Contracts
Fault Contracts
![Page 14: Dotnet3.5_WCF](https://reader030.fdocuments.in/reader030/viewer/2022021316/577cc8cd1a28aba711a33e14/html5/thumbnails/14.jpg)
8/12/2019 Dotnet3.5_WCF
http://slidepdf.com/reader/full/dotnet35wcf 14/33Confidential ©2009 Syntel, Inc.
Service Contracts
A service contract defines the operations that a service
supports, and maps to a portType in Web ServiceDescription Language (WSDL)
Service contracts are implemented as .NET Framework
interfaces that are annotated with the ServiceContract
attribute[ServiceContract]
public interface IBookOrder{ ...}
![Page 15: Dotnet3.5_WCF](https://reader030.fdocuments.in/reader030/viewer/2022021316/577cc8cd1a28aba711a33e14/html5/thumbnails/15.jpg)
8/12/2019 Dotnet3.5_WCF
http://slidepdf.com/reader/full/dotnet35wcf 15/33Confidential ©2009 Syntel, Inc.
Operation Contracts
Operation contracts define the individual operations that a
service supports and map to operations in WSDL
Operations are defined by adding methods to a Service
Contract interface that is annotated with the
OperationContract attribute
[OperationContract]void SomeOperation();
![Page 16: Dotnet3.5_WCF](https://reader030.fdocuments.in/reader030/viewer/2022021316/577cc8cd1a28aba711a33e14/html5/thumbnails/16.jpg)
8/12/2019 Dotnet3.5_WCF
http://slidepdf.com/reader/full/dotnet35wcf 16/33
![Page 17: Dotnet3.5_WCF](https://reader030.fdocuments.in/reader030/viewer/2022021316/577cc8cd1a28aba711a33e14/html5/thumbnails/17.jpg)
8/12/2019 Dotnet3.5_WCF
http://slidepdf.com/reader/full/dotnet35wcf 17/33Confidential ©2009 Syntel, Inc.
Message Contracts
Message contracts provide a simple method to add custom
SOAP headers to incoming and outgoing messages
[MessageContract]
public class MyRequest {
[MessageHeader] public string field1;
[MessageBody] public string field2;}
![Page 18: Dotnet3.5_WCF](https://reader030.fdocuments.in/reader030/viewer/2022021316/577cc8cd1a28aba711a33e14/html5/thumbnails/18.jpg)
8/12/2019 Dotnet3.5_WCF
http://slidepdf.com/reader/full/dotnet35wcf 18/33Confidential ©2009 Syntel, Inc.
Fault Contracts
[OperationContract]
[FaultContract(typeof(DivideByZeroException))]void SomeMethod();
A Fault is generated by throwing a FaultException:
throw new
FaultException<DivideByZeroException>(someException);
![Page 19: Dotnet3.5_WCF](https://reader030.fdocuments.in/reader030/viewer/2022021316/577cc8cd1a28aba711a33e14/html5/thumbnails/19.jpg)
8/12/2019 Dotnet3.5_WCF
http://slidepdf.com/reader/full/dotnet35wcf 19/33Confidential ©2009 Syntel, Inc.
Example: Contract
[ServiceContract]
public interface IOrderService{
[OperationContract]void CreateOrder(int orderNumber);
[OperationContract]void AddItemToOrder(int orderNumber, Item itm);
[OperationContract]Order GetOrderDetails(int orderNumber);
}
![Page 20: Dotnet3.5_WCF](https://reader030.fdocuments.in/reader030/viewer/2022021316/577cc8cd1a28aba711a33e14/html5/thumbnails/20.jpg)
8/12/2019 Dotnet3.5_WCF
http://slidepdf.com/reader/full/dotnet35wcf 20/33Confidential ©2009 Syntel, Inc.
Example : Service
public class OrderService : IOrderService
{ void CreateOrder(int orderNumber){
// implementation details}
void AddItemToOrder(int orderNumber, Item itm){
// implementation details}
Order GetOrderDetails(int orderNumber){// implementation details
}}
![Page 21: Dotnet3.5_WCF](https://reader030.fdocuments.in/reader030/viewer/2022021316/577cc8cd1a28aba711a33e14/html5/thumbnails/21.jpg)
8/12/2019 Dotnet3.5_WCF
http://slidepdf.com/reader/full/dotnet35wcf 21/33Confidential ©2009 Syntel, Inc.
Example : Data Contract
[DataContract]
public class Order{
[DataMember]
public int OrderNumber;
[DataMember]public String ClientName;
...
}
![Page 22: Dotnet3.5_WCF](https://reader030.fdocuments.in/reader030/viewer/2022021316/577cc8cd1a28aba711a33e14/html5/thumbnails/22.jpg)
8/12/2019 Dotnet3.5_WCF
http://slidepdf.com/reader/full/dotnet35wcf 22/33Confidential ©2009 Syntel, Inc.
WCF Addresses
Service endpoints are exposed through addresses
Every endpoint must have an address so that other
programs can communicate with it
Windows Communication Foundation lets you use several
types of addresses to associate with each endpoint, and it is
through these addresses that the client communicates withthe endpoint
For example, an address might look like the following:
http://mymachine:8080/myservice
![Page 23: Dotnet3.5_WCF](https://reader030.fdocuments.in/reader030/viewer/2022021316/577cc8cd1a28aba711a33e14/html5/thumbnails/23.jpg)
8/12/2019 Dotnet3.5_WCF
http://slidepdf.com/reader/full/dotnet35wcf 23/33Confidential ©2009 Syntel, Inc.
WCF Bindings
A WCF binding is an object that specifies how to connect to
the endpoint of a WCF service, and each endpoint musthave a binding associated with it
WCF ships with a number of predefined bindings that cover
most common scenarios, although it is also possible to
create custom bindings
![Page 24: Dotnet3.5_WCF](https://reader030.fdocuments.in/reader030/viewer/2022021316/577cc8cd1a28aba711a33e14/html5/thumbnails/24.jpg)
8/12/2019 Dotnet3.5_WCF
http://slidepdf.com/reader/full/dotnet35wcf 24/33Confidential ©2009 Syntel, Inc.
What do Bindings Define?
A binding contains the following three categories of
information:1. Protocol information, such as the security mechanism that is being
used, and the reliable messaging and transaction settings
2. Information about the underlying transport protocol to use, such as
TCP or HTTP
3. Information about the message encoding, for example, Text or XML,
Binary, or Message Transmission Optimization Mechanism (MTOM)
![Page 25: Dotnet3.5_WCF](https://reader030.fdocuments.in/reader030/viewer/2022021316/577cc8cd1a28aba711a33e14/html5/thumbnails/25.jpg)
8/12/2019 Dotnet3.5_WCF
http://slidepdf.com/reader/full/dotnet35wcf 25/33Confidential ©2009 Syntel, Inc.
What do Bindings Define?
Bindings contain a collection of binding elements, such as
SecurityBindingElement and TcpTransportElement, whichdefine a communication stack, and the operation of the
stack depends on the order in which the binding elements
were added to the collection
![Page 26: Dotnet3.5_WCF](https://reader030.fdocuments.in/reader030/viewer/2022021316/577cc8cd1a28aba711a33e14/html5/thumbnails/26.jpg)
8/12/2019 Dotnet3.5_WCF
http://slidepdf.com/reader/full/dotnet35wcf 26/33Confidential ©2009 Syntel, Inc.
Predefined WCF Bindings
Binding information can be complex, and not all options may be
compatibleFor this reason, WCF provides a set of predefined combinations of
binding elements that are appropriate for many common scenarios
For example, BasicHttpBinding enables basic Web service
communication by using text or HTML, with WSHttpBinding also
supporting many of the WS-* standardsNote: Bindings are covered in details later
![Page 27: Dotnet3.5_WCF](https://reader030.fdocuments.in/reader030/viewer/2022021316/577cc8cd1a28aba711a33e14/html5/thumbnails/27.jpg)
8/12/2019 Dotnet3.5_WCF
http://slidepdf.com/reader/full/dotnet35wcf 27/33Confidential ©2009 Syntel, Inc.
Specifying Bindings
All types of bindings, including custom or predefined, can be
specified in configuration files or in code
By defining bindings in code, the developer gains complete
control over the definition at design time, but by specifying
binding information in configuration files, the binding
information can be changed without recompiling the code
![Page 28: Dotnet3.5_WCF](https://reader030.fdocuments.in/reader030/viewer/2022021316/577cc8cd1a28aba711a33e14/html5/thumbnails/28.jpg)
8/12/2019 Dotnet3.5_WCF
http://slidepdf.com/reader/full/dotnet35wcf 28/33Confidential ©2009 Syntel, Inc.
Service Configuration in WCF
WCF services can be configured in code or by using
configuration files
If you are hosting a service in IIS, you use the web.config
file, but you use the application configuration file for any
other application
Each service must have an endpoint defined
![Page 29: Dotnet3.5_WCF](https://reader030.fdocuments.in/reader030/viewer/2022021316/577cc8cd1a28aba711a33e14/html5/thumbnails/29.jpg)
8/12/2019 Dotnet3.5_WCF
http://slidepdf.com/reader/full/dotnet35wcf 29/33Confidential ©2009 Syntel, Inc.
Service Configuration in WCF
An endpoint consists of an address that shows where the
endpoint is located, a binding that specifies communicationinformation, and a service contract that identifies the
methods that the service supports
An endpoint address contains a URI as well as other
optional properties, such as an identity, WSDL elements,and headers
The optional properties can be used for tasks, such as
routing incoming messages or deciding where to send a
reply
![Page 30: Dotnet3.5_WCF](https://reader030.fdocuments.in/reader030/viewer/2022021316/577cc8cd1a28aba711a33e14/html5/thumbnails/30.jpg)
8/12/2019 Dotnet3.5_WCF
http://slidepdf.com/reader/full/dotnet35wcf 30/33
![Page 31: Dotnet3.5_WCF](https://reader030.fdocuments.in/reader030/viewer/2022021316/577cc8cd1a28aba711a33e14/html5/thumbnails/31.jpg)
8/12/2019 Dotnet3.5_WCF
http://slidepdf.com/reader/full/dotnet35wcf 31/33
Confidential ©2009 Syntel, Inc.
Defining Endpoints in Configuration Files
To set up endpoints in configuration files, define <endpoint>
elements within a parent <service> element inside the<system.ServiceModel> section of your configuration file
<endpoint
address="http://localhost/MathService/Ep1"
binding="wsHttpBinding"contract="IMath"/>
![Page 32: Dotnet3.5_WCF](https://reader030.fdocuments.in/reader030/viewer/2022021316/577cc8cd1a28aba711a33e14/html5/thumbnails/32.jpg)
8/12/2019 Dotnet3.5_WCF
http://slidepdf.com/reader/full/dotnet35wcf 32/33
Confidential ©2009 Syntel, Inc.
Demo – Creating a WCF Service
![Page 33: Dotnet3.5_WCF](https://reader030.fdocuments.in/reader030/viewer/2022021316/577cc8cd1a28aba711a33e14/html5/thumbnails/33.jpg)
8/12/2019 Dotnet3.5_WCF
http://slidepdf.com/reader/full/dotnet35wcf 33/33
Options for Hosting a WCF Service
WCF is flexible because its services can be hosted in
different types of applications
The following lists several common scenarios for hosting
WCF services:
IIS
WAS Self-hosting
Managed Windows Service