SlideShare ist ein Scribd-Unternehmen logo
1 von 36
http://debugmode.net




Getting Started with
        WCF
           Dhananjay Kumar
           @debug_mode
What definition you get on web ?
Service Oriented programming model to
develop connected applications


SDK to develop and deploy services on windows

Unifies the existing suite of .Net distributed
technologies into a single programming model.

                Microsoft Innovation & Practice Team,
                                              MSCoE     2
Getting Started with WCF




Developer Evangelist Telerik

Microsoft MVP

Mindcracker MVP

@debug_mode

fb.com/debugmode.net

Delhi User Group

C-Sharp corner User Group
Services and Clients



     Service   Message   Client
Let us start
with a Demo
Endpoints


  Client                      Service

                          Endpoint

     Endpoint   Message   Endpoint
End Points




  A          B   C   E


                         7
End Points


                          Contracts
             Address



                       Binding




              End Point
                                      8
End Point

ADDRESS
           •Where
BINDING
           •How
CONTRACT
           •What
9
Address (A)
Every service is associated with a unique
  address.

         Location of
         the Service

                          Address
                           of the
          Transport
                          Service
           protocol
           used in
            service

                                            10
Address (A)

Address specifies where the service is residing.


This is an URL( Uniform Resource Locator).


Address URL identifies , location of the service

Address should follow the Web Service
Addressing(WS-Addressing) standard.
                                                   11
Address (A)


                 WS
              Addressing

Scheme   Machine       Port   Path



                                     12
Address (A)

              • This is top level portion of the address.
 Scheme         This is not as same as of protocols.

              • This identifies the machine name. This
Machine         can be a public URL or a local identifier

              • This is port number. This is an optional
   Port         part.

              • This is used to locate the path. This
   Path         gives path of the service.
                                                        13
Address (A)
               • http://localhost:8001/Dell
   HTTP        • http://localhost/Dell

               • net.tcp://localhost:800/Dell
    TCP        • net.tcp://localhost/Dell

               • net.msmq/private/MyService
  MSMQ         • Net.msmq/://localhost/Dell


               • net.pipe://localhost/MyPipe
    IPC




               • Net.pipe://localhost.MyService
Peer network



                                                  14
Binding (B)
Describes how a service communicates.


This specifies which Protocol to be used.


This specifies the encoding method to format the message content.


This specifies the Security requirements


This specifies the message exchange format.


This specifies message session mode.

Developer could create custom Binding also.
15
Binding (B)
Transport Protocol

Message Encoding

Communication Pattern

Security

Transaction Property

Inter Operability

16
Binding (B)
      Choosing Binding

                  No           WCF      Yes
                                To
                               WCF



                                                        No                        Yes
                                                                   Disconnected
                                                                       Calls



 No                Yes
         Legacy                        No                    Yes
                                              Cross
          ASMX                                Machine




WS                     Basic         IPC                       TCP                      MSMQ


 17
Binding (B)
Binding Classes
Binding Name as of class   Transport    Encoding    Interoperable

BasicHttpBinding           HTTP/HTTPS   Text,MTOM   Yes
NetTcpBinding              TCP          Binary      No
NetPeerBinding             P2P          Binary      No
NetNamedPipeBinding        IPC          Binary      No
WSHttpBinding              HTTP/HTTPS   Text,MTOM   Yes
WSFederationHttpBinding    HTTP/HTTPS   Text,MTOM   Yes
WSDualHttpBinding          HTTP         Text,MTOM   Yes
NetMsmqBinding             MSMQ         Binary      No
MsmqIntegrationBinding     MSMQ         Binary      Yes

18
Binding (B)
Configuring Binding

     <endpoint address="Calculator"
               bindingSectionName="basicProfileBinding"
               bindingConfiguration="Binding1"
               contractType="ICalculator" />
     <bindings>
       <basicProfileBinding>
         <binding configurationName="Binding1"
                  hostnameComparisonMode="StrongWildcard"
                  transferTimeout="00:10:00"
                  maxMessageSize="65536"
                  messageEncoding="Text"
                  textEncoding="utf-8"
         </binding>
       </basicProfileBinding>
     </bindings>
19
Service Contract (C)

A WCF Contract is a collection of Operations


All WCF services exposes contract.

This is a platform neutral and standard way to say , what
the service will do.

Defines , what a Service communicates.

20
Contract (C)
Types of Contracts
 Service • Describes which operation client can perform on the services.
Contract

           • Defines which Data Type are passed to and from the services. It provides built-
  Data       in contract for implicit type.
Contract

           • Which error raise by service and how service propagates and handles error to its
 Fault       client.
Contract

         • Allow the service to interact directly with the message . Message contract can
Message    be typed or un typed. This can be used for interoperability.
Contract


21                                                                                              21
Contract (C)
 Service Contract

A Service Contract reflects specific business


Describe which operations client can
perform

Maps CLR types to WSDL
 22
Contract (C)
 Service Contract

Interfaces are used to explicitly define a Contract


Classes may also be used to define a Contract.

[ServiceContract] attribute is being used by
interface/class to qualify them as a contract.

ServiceContract are implicitly public.
 23
Contract (C)
Service Contract
     // Define a service contract.
     [ServiceContract(Namespace="http://Microsoft.ServiceModel.Samples")]
     public interface IDataContractCalculator
     {
         [OperationContract]
         ComplexNumber Add(ComplexNumber n1, ComplexNumber n2);
         [OperationContract]
         ComplexNumber Subtract(ComplexNumber n1, ComplexNumber n2);
         [OperationContract]
         ComplexNumber Multiply(ComplexNumber n1, ComplexNumber n2);
         [OperationContract]
         ComplexNumber Divide(ComplexNumber n1, ComplexNumber n2);
     }




24
Contract (C)
Data Contract
These are the contractual agreement about the format
and structure of the payload data in message exchange
between a service and its consumer.

Defines which Data types are passed to and from the
service.


Its specifies CLR type to XML schema.
25
Contract (C)
 Data Contract
DataContract are preferred WCF way to enable
Serialization.

WCF defines implicit contract for built in types like int and
string.

Developer has to explicitly expose complex types as Data
Contract.

[DataContract] and [DataMember] attribute are used to
define a type as Data Contract.
 26
Contract (C)
Data Contract

     [DataContract]
     public class ComplexNumber
     {
         [DataMember]
         public double Real = 0.0D;
         [DataMember]
         public double Imaginary = 0.0D;
     }


27
Contract (C)
 Message Contract
It gives control over SOAP message structure on both header and body
content.

Developer can designate optional SOAP headers.


It provides additional control over the WSDL generation.


It is used to interoperate with another non- WCF service.


It is used to control security issue at level of message.
 28
Contract (C)
 Fault Contract

This translates .Net Exception to SOAP fault propagated to consumer


This can be applied to operation only.


This is not Inheritable.


This can be applied multiple times.

This enables developer to declare which faults a given service operation
might issue if things goes wrong.
 29
Creating End Point


Could be created declaratively in configuration file.


Could be created imperatively through code.

Any thing done through code can be done with configuration file and
vice versa.

It is considered good practice to use configuration file to specify End
points. This accommodates changes without recompiling the code.
 30
Defining Endpoints


<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
  <system.serviceModel>
    <services>
      <service serviceType="CalculatorService">
        <endpoint address="Calculator"
                  bindingSectionName="basicProfileBinding"
                  contractType="ICalculator" />
      </service>
    </services>
  </system.serviceModel>
</configuration>
Multiple End Point

For service exposed to multiple clients ; it makes sense to
specify more than one End point.

This enables client to use the endpoint that is most
applicable for them.

When creating multiple endpoints each client must have
unique address

If two client uses the same address , error will raise at
service load time.
  32
Multiple End Point
• <endpoint address="http://localhost:8890/a"
  binding="wsHttpBinding"
  contract="HotsingSamples.IService1"/>
• <endpoint address="http://localhost:8000/b"
  binding="basicHttpBinding"
  contract="HotsingSamples.IService1"/>
• <endpoint address="net.tcp://localhost:8001/c"
  binding="netTcpBinding"
  contract="HotsingSamples.IService1"/>


33
Hosting
WCF services can not exist in void.


It must be hosted.

WCF services are hosted in windows process called host
process.

A single host process can host multiple service.


A same service can be hosted in multiple host process.
 34
WCF basic task cycle

                             1.
                         Defining
                          Service
                         Contract
                                              2.
           5.                             Impleme
        Building                            nting
         Clients                           Service
                                          Contract



                                       3.
                 4.
                                    Configuri
              Hosting
                                       ng
              Services
                                    Services

                                                     35
DEBUG_MODE           http://debugmode.net




             Dhananjay Kumar

Weitere ähnliche Inhalte

Was ist angesagt?

Interoperability and Windows Communication Foundation (WCF) Overview
Interoperability and Windows Communication Foundation (WCF) OverviewInteroperability and Windows Communication Foundation (WCF) Overview
Interoperability and Windows Communication Foundation (WCF) Overview
Jorgen Thelin
 
WCF (Windows Communication Foundation)
WCF (Windows Communication Foundation)WCF (Windows Communication Foundation)
WCF (Windows Communication Foundation)
ipower softwares
 
Windows Communication Foundation (WCF) Service
Windows Communication Foundation (WCF) ServiceWindows Communication Foundation (WCF) Service
Windows Communication Foundation (WCF) Service
Sj Lim
 
Beginning with wcf service
Beginning with wcf serviceBeginning with wcf service
Beginning with wcf service
Binu Bhasuran
 
1. WCF Services - Exam 70-487
1. WCF Services - Exam 70-4871. WCF Services - Exam 70-487
1. WCF Services - Exam 70-487
Bat Programmer
 
Session 1: The SOAP Story
Session 1: The SOAP StorySession 1: The SOAP Story
Session 1: The SOAP Story
ukdpe
 

Was ist angesagt? (20)

Interoperability and Windows Communication Foundation (WCF) Overview
Interoperability and Windows Communication Foundation (WCF) OverviewInteroperability and Windows Communication Foundation (WCF) Overview
Interoperability and Windows Communication Foundation (WCF) Overview
 
Building RESTful Services with WCF 4.0
Building RESTful Services with WCF 4.0Building RESTful Services with WCF 4.0
Building RESTful Services with WCF 4.0
 
Wcf
WcfWcf
Wcf
 
WCF tutorial
WCF tutorialWCF tutorial
WCF tutorial
 
WCF (Windows Communication Foundation)
WCF (Windows Communication Foundation)WCF (Windows Communication Foundation)
WCF (Windows Communication Foundation)
 
Wcf development
Wcf developmentWcf development
Wcf development
 
REST, JSON and RSS with WCF 3.5
REST, JSON and RSS with WCF 3.5REST, JSON and RSS with WCF 3.5
REST, JSON and RSS with WCF 3.5
 
WCF
WCFWCF
WCF
 
Windows Communication Foundation (WCF) Best Practices
Windows Communication Foundation (WCF) Best PracticesWindows Communication Foundation (WCF) Best Practices
Windows Communication Foundation (WCF) Best Practices
 
Windows Communication Foundation (WCF) Service
Windows Communication Foundation (WCF) ServiceWindows Communication Foundation (WCF) Service
Windows Communication Foundation (WCF) Service
 
WCF
WCFWCF
WCF
 
Advancio, Inc. Academy: Web Sevices, WCF & SOAPUI
Advancio, Inc. Academy: Web Sevices, WCF & SOAPUIAdvancio, Inc. Academy: Web Sevices, WCF & SOAPUI
Advancio, Inc. Academy: Web Sevices, WCF & SOAPUI
 
Enjoying the Move from WCF to the Web API
Enjoying the Move from WCF to the Web APIEnjoying the Move from WCF to the Web API
Enjoying the Move from WCF to the Web API
 
introduction to Windows Comunication Foundation
introduction to Windows Comunication Foundationintroduction to Windows Comunication Foundation
introduction to Windows Comunication Foundation
 
Beginning with wcf service
Beginning with wcf serviceBeginning with wcf service
Beginning with wcf service
 
1. WCF Services - Exam 70-487
1. WCF Services - Exam 70-4871. WCF Services - Exam 70-487
1. WCF Services - Exam 70-487
 
Session 1: The SOAP Story
Session 1: The SOAP StorySession 1: The SOAP Story
Session 1: The SOAP Story
 
Web services, WCF services and Multi Threading with Windows Forms
Web services, WCF services and Multi Threading with Windows FormsWeb services, WCF services and Multi Threading with Windows Forms
Web services, WCF services and Multi Threading with Windows Forms
 
Windows Communication Foundation
Windows Communication FoundationWindows Communication Foundation
Windows Communication Foundation
 
Simple object access protocol(soap )
Simple object access protocol(soap )Simple object access protocol(soap )
Simple object access protocol(soap )
 

Ähnlich wie WCF for begineers

Dot Net Training Wcf Dot Net35
Dot Net Training Wcf Dot Net35Dot Net Training Wcf Dot Net35
Dot Net Training Wcf Dot Net35
Subodh Pushpak
 
A presentation on WCF & REST
A presentation on WCF & RESTA presentation on WCF & REST
A presentation on WCF & REST
Santhu Rao
 
Web services
Web servicesWeb services
Web services
aspnet123
 

Ähnlich wie WCF for begineers (20)

Dot Net Training Wcf Dot Net35
Dot Net Training Wcf Dot Net35Dot Net Training Wcf Dot Net35
Dot Net Training Wcf Dot Net35
 
Wcf faq
Wcf faqWcf faq
Wcf faq
 
A presentation on WCF & REST
A presentation on WCF & RESTA presentation on WCF & REST
A presentation on WCF & REST
 
Wcf best practice
Wcf best practiceWcf best practice
Wcf best practice
 
WCF (Windows Communication Foundation_Unit_01)
WCF (Windows Communication Foundation_Unit_01)WCF (Windows Communication Foundation_Unit_01)
WCF (Windows Communication Foundation_Unit_01)
 
Top wcf interview questions
Top wcf interview questionsTop wcf interview questions
Top wcf interview questions
 
Basics of WCF and its Security
Basics of WCF and its SecurityBasics of WCF and its Security
Basics of WCF and its Security
 
web programming
web programmingweb programming
web programming
 
Understanding Web Services by software outsourcing company india
Understanding Web Services by software outsourcing company indiaUnderstanding Web Services by software outsourcing company india
Understanding Web Services by software outsourcing company india
 
Cloud Presentation.pdf
Cloud Presentation.pdfCloud Presentation.pdf
Cloud Presentation.pdf
 
Client server chat application
Client server chat applicationClient server chat application
Client server chat application
 
Presentation1.pptx
Presentation1.pptxPresentation1.pptx
Presentation1.pptx
 
Complete Architecture and Development Guide To Windows Communication Foundati...
Complete Architecture and Development Guide To Windows Communication Foundati...Complete Architecture and Development Guide To Windows Communication Foundati...
Complete Architecture and Development Guide To Windows Communication Foundati...
 
Consul: Service Mesh for Microservices
Consul: Service Mesh for MicroservicesConsul: Service Mesh for Microservices
Consul: Service Mesh for Microservices
 
6. The grid-COMPUTING OGSA and WSRF
6. The grid-COMPUTING OGSA and WSRF6. The grid-COMPUTING OGSA and WSRF
6. The grid-COMPUTING OGSA and WSRF
 
07 advanced topics
07 advanced topics07 advanced topics
07 advanced topics
 
Web services
Web servicesWeb services
Web services
 
Java Network Programming.pptx
Java Network Programming.pptxJava Network Programming.pptx
Java Network Programming.pptx
 
Wcf
Wcf Wcf
Wcf
 
WCF 4 Overview
WCF 4 OverviewWCF 4 Overview
WCF 4 Overview
 

Mehr von Dhananjay Kumar

Slides of webinar Kendo UI and Knockout.js
Slides of webinar Kendo UI and Knockout.jsSlides of webinar Kendo UI and Knockout.js
Slides of webinar Kendo UI and Knockout.js
Dhananjay Kumar
 
Presenter deck icenium hol
Presenter deck   icenium holPresenter deck   icenium hol
Presenter deck icenium hol
Dhananjay Kumar
 
Windows azure mobile service
Windows azure mobile serviceWindows azure mobile service
Windows azure mobile service
Dhananjay Kumar
 
Functions and Objects in JavaScript
Functions and Objects in JavaScript Functions and Objects in JavaScript
Functions and Objects in JavaScript
Dhananjay Kumar
 
Windows aazuremobileservices
Windows aazuremobileservicesWindows aazuremobileservices
Windows aazuremobileservices
Dhananjay Kumar
 
Rad controlforwindows25thapril
Rad controlforwindows25thaprilRad controlforwindows25thapril
Rad controlforwindows25thapril
Dhananjay Kumar
 
Windows storemindcrcaker23rdmarch
Windows storemindcrcaker23rdmarchWindows storemindcrcaker23rdmarch
Windows storemindcrcaker23rdmarch
Dhananjay Kumar
 

Mehr von Dhananjay Kumar (20)

Slides of webinar Kendo UI and Knockout.js
Slides of webinar Kendo UI and Knockout.jsSlides of webinar Kendo UI and Knockout.js
Slides of webinar Kendo UI and Knockout.js
 
Nodejsvs
NodejsvsNodejsvs
Nodejsvs
 
Node.js
Node.jsNode.js
Node.js
 
No SQL with Kendo UI
No SQL with Kendo UI No SQL with Kendo UI
No SQL with Kendo UI
 
Patterns in JavaScript
Patterns in JavaScriptPatterns in JavaScript
Patterns in JavaScript
 
Presenter deck icenium hol
Presenter deck   icenium holPresenter deck   icenium hol
Presenter deck icenium hol
 
Bringbestoinyou
BringbestoinyouBringbestoinyou
Bringbestoinyou
 
Java script
Java scriptJava script
Java script
 
Windows azure mobile service
Windows azure mobile serviceWindows azure mobile service
Windows azure mobile service
 
Test studiowebinaraugcodedstep
Test studiowebinaraugcodedstepTest studiowebinaraugcodedstep
Test studiowebinaraugcodedstep
 
Functions and Objects in JavaScript
Functions and Objects in JavaScript Functions and Objects in JavaScript
Functions and Objects in JavaScript
 
Create Hybrid Mobile Application with Icenium and Kendo UI Mobile
Create Hybrid Mobile Application with Icenium and Kendo UI Mobile Create Hybrid Mobile Application with Icenium and Kendo UI Mobile
Create Hybrid Mobile Application with Icenium and Kendo UI Mobile
 
Cloud Based Enterprise Apps using Everlive
Cloud Based Enterprise Apps using EverliveCloud Based Enterprise Apps using Everlive
Cloud Based Enterprise Apps using Everlive
 
A Look into Automated Web UI Test
A Look into Automated Web UI TestA Look into Automated Web UI Test
A Look into Automated Web UI Test
 
Windows phone 8 app using Kendo UI
Windows phone 8 app using Kendo UI Windows phone 8 app using Kendo UI
Windows phone 8 app using Kendo UI
 
Cross platformmobileapp
Cross platformmobileappCross platformmobileapp
Cross platformmobileapp
 
Windows aazuremobileservices
Windows aazuremobileservicesWindows aazuremobileservices
Windows aazuremobileservices
 
Rad controlforwindows25thapril
Rad controlforwindows25thaprilRad controlforwindows25thapril
Rad controlforwindows25thapril
 
Data asservice
Data asserviceData asservice
Data asservice
 
Windows storemindcrcaker23rdmarch
Windows storemindcrcaker23rdmarchWindows storemindcrcaker23rdmarch
Windows storemindcrcaker23rdmarch
 

Kürzlich hochgeladen

Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 

Kürzlich hochgeladen (20)

ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Role Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxRole Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 

WCF for begineers

  • 1. http://debugmode.net Getting Started with WCF Dhananjay Kumar @debug_mode
  • 2. What definition you get on web ? Service Oriented programming model to develop connected applications SDK to develop and deploy services on windows Unifies the existing suite of .Net distributed technologies into a single programming model. Microsoft Innovation & Practice Team, MSCoE 2
  • 3. Getting Started with WCF Developer Evangelist Telerik Microsoft MVP Mindcracker MVP @debug_mode fb.com/debugmode.net Delhi User Group C-Sharp corner User Group
  • 4. Services and Clients Service Message Client
  • 6. Endpoints Client Service Endpoint Endpoint Message Endpoint
  • 7. End Points A B C E 7
  • 8. End Points Contracts Address Binding End Point 8
  • 9. End Point ADDRESS •Where BINDING •How CONTRACT •What 9
  • 10. Address (A) Every service is associated with a unique address. Location of the Service Address of the Transport Service protocol used in service 10
  • 11. Address (A) Address specifies where the service is residing. This is an URL( Uniform Resource Locator). Address URL identifies , location of the service Address should follow the Web Service Addressing(WS-Addressing) standard. 11
  • 12. Address (A) WS Addressing Scheme Machine Port Path 12
  • 13. Address (A) • This is top level portion of the address. Scheme This is not as same as of protocols. • This identifies the machine name. This Machine can be a public URL or a local identifier • This is port number. This is an optional Port part. • This is used to locate the path. This Path gives path of the service. 13
  • 14. Address (A) • http://localhost:8001/Dell HTTP • http://localhost/Dell • net.tcp://localhost:800/Dell TCP • net.tcp://localhost/Dell • net.msmq/private/MyService MSMQ • Net.msmq/://localhost/Dell • net.pipe://localhost/MyPipe IPC • Net.pipe://localhost.MyService Peer network 14
  • 15. Binding (B) Describes how a service communicates. This specifies which Protocol to be used. This specifies the encoding method to format the message content. This specifies the Security requirements This specifies the message exchange format. This specifies message session mode. Developer could create custom Binding also. 15
  • 16. Binding (B) Transport Protocol Message Encoding Communication Pattern Security Transaction Property Inter Operability 16
  • 17. Binding (B) Choosing Binding No WCF Yes To WCF No Yes Disconnected Calls No Yes Legacy No Yes Cross ASMX Machine WS Basic IPC TCP MSMQ 17
  • 18. Binding (B) Binding Classes Binding Name as of class Transport Encoding Interoperable BasicHttpBinding HTTP/HTTPS Text,MTOM Yes NetTcpBinding TCP Binary No NetPeerBinding P2P Binary No NetNamedPipeBinding IPC Binary No WSHttpBinding HTTP/HTTPS Text,MTOM Yes WSFederationHttpBinding HTTP/HTTPS Text,MTOM Yes WSDualHttpBinding HTTP Text,MTOM Yes NetMsmqBinding MSMQ Binary No MsmqIntegrationBinding MSMQ Binary Yes 18
  • 19. Binding (B) Configuring Binding <endpoint address="Calculator" bindingSectionName="basicProfileBinding" bindingConfiguration="Binding1" contractType="ICalculator" /> <bindings> <basicProfileBinding> <binding configurationName="Binding1" hostnameComparisonMode="StrongWildcard" transferTimeout="00:10:00" maxMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" </binding> </basicProfileBinding> </bindings> 19
  • 20. Service Contract (C) A WCF Contract is a collection of Operations All WCF services exposes contract. This is a platform neutral and standard way to say , what the service will do. Defines , what a Service communicates. 20
  • 21. Contract (C) Types of Contracts Service • Describes which operation client can perform on the services. Contract • Defines which Data Type are passed to and from the services. It provides built- Data in contract for implicit type. Contract • Which error raise by service and how service propagates and handles error to its Fault client. Contract • Allow the service to interact directly with the message . Message contract can Message be typed or un typed. This can be used for interoperability. Contract 21 21
  • 22. Contract (C) Service Contract A Service Contract reflects specific business Describe which operations client can perform Maps CLR types to WSDL 22
  • 23. Contract (C) Service Contract Interfaces are used to explicitly define a Contract Classes may also be used to define a Contract. [ServiceContract] attribute is being used by interface/class to qualify them as a contract. ServiceContract are implicitly public. 23
  • 24. Contract (C) Service Contract // Define a service contract. [ServiceContract(Namespace="http://Microsoft.ServiceModel.Samples")] public interface IDataContractCalculator { [OperationContract] ComplexNumber Add(ComplexNumber n1, ComplexNumber n2); [OperationContract] ComplexNumber Subtract(ComplexNumber n1, ComplexNumber n2); [OperationContract] ComplexNumber Multiply(ComplexNumber n1, ComplexNumber n2); [OperationContract] ComplexNumber Divide(ComplexNumber n1, ComplexNumber n2); } 24
  • 25. Contract (C) Data Contract These are the contractual agreement about the format and structure of the payload data in message exchange between a service and its consumer. Defines which Data types are passed to and from the service. Its specifies CLR type to XML schema. 25
  • 26. Contract (C) Data Contract DataContract are preferred WCF way to enable Serialization. WCF defines implicit contract for built in types like int and string. Developer has to explicitly expose complex types as Data Contract. [DataContract] and [DataMember] attribute are used to define a type as Data Contract. 26
  • 27. Contract (C) Data Contract [DataContract] public class ComplexNumber { [DataMember] public double Real = 0.0D; [DataMember] public double Imaginary = 0.0D; } 27
  • 28. Contract (C) Message Contract It gives control over SOAP message structure on both header and body content. Developer can designate optional SOAP headers. It provides additional control over the WSDL generation. It is used to interoperate with another non- WCF service. It is used to control security issue at level of message. 28
  • 29. Contract (C) Fault Contract This translates .Net Exception to SOAP fault propagated to consumer This can be applied to operation only. This is not Inheritable. This can be applied multiple times. This enables developer to declare which faults a given service operation might issue if things goes wrong. 29
  • 30. Creating End Point Could be created declaratively in configuration file. Could be created imperatively through code. Any thing done through code can be done with configuration file and vice versa. It is considered good practice to use configuration file to specify End points. This accommodates changes without recompiling the code. 30
  • 31. Defining Endpoints <?xml version="1.0" encoding="utf-8" ?> <configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0"> <system.serviceModel> <services> <service serviceType="CalculatorService"> <endpoint address="Calculator" bindingSectionName="basicProfileBinding" contractType="ICalculator" /> </service> </services> </system.serviceModel> </configuration>
  • 32. Multiple End Point For service exposed to multiple clients ; it makes sense to specify more than one End point. This enables client to use the endpoint that is most applicable for them. When creating multiple endpoints each client must have unique address If two client uses the same address , error will raise at service load time. 32
  • 33. Multiple End Point • <endpoint address="http://localhost:8890/a" binding="wsHttpBinding" contract="HotsingSamples.IService1"/> • <endpoint address="http://localhost:8000/b" binding="basicHttpBinding" contract="HotsingSamples.IService1"/> • <endpoint address="net.tcp://localhost:8001/c" binding="netTcpBinding" contract="HotsingSamples.IService1"/> 33
  • 34. Hosting WCF services can not exist in void. It must be hosted. WCF services are hosted in windows process called host process. A single host process can host multiple service. A same service can be hosted in multiple host process. 34
  • 35. WCF basic task cycle 1. Defining Service Contract 2. 5. Impleme Building nting Clients Service Contract 3. 4. Configuri Hosting ng Services Services 35
  • 36. DEBUG_MODE http://debugmode.net Dhananjay Kumar