SlideShare a Scribd company logo
Exposing Data Using WCF


Shannon Richards
Associate Principal Consultant
Email: shannonr@magenic.com
Expectations
» Overview of WCF…
» This presentation will set the stage for the following presentations…


» If you’re new to WCF – I hope you walk away excited about how WCF can
  fit into your projects!

» If you’re experienced with WCF – I hope you pick up on something new!

» Patience is a virtue – You will not become a WCF expert overnight!
SOA Overview
» What is SOA?
  » Service-oriented architecture…
  » It is an evolution of distributed computing based on a model of loose
    coupling and software composition.
  » The ubiquity of [and almost universal support for] TCP/IP, HTTP and
    XML technologies have created an environment where interoperability
    through services is achievable.
  » Relies on metadata to describe not only the characteristics of services,
    but also the data that drives them.
SOA Overview – Continued
SOA Overview – Continued
» Why SOA?
  » The reality of life in modern IT organizations is that infrastructure is
    heterogeneous across operating systems, applications, system
    software and application infrastructure…
  » Allows business to leverage existing investments in applications and
    infrastructure to satisfy evolving business needs:
     » Wrap existing functionality with services and expose them for consumption by
       other applications.
  » Loose coupling:
     » Rather than being bound to an operating system, a development platform or a
       binary API, SOA defines interactions in terms of contracts and protocols.
  » Ability to more quickly adapt as business process inevitably changes:
     » Services can be rapidly developed, deployed, refactored and consumed by existing
       software systems.
WCF
» What is WCF?
» Windows Communication Foundation
» Microsoft’s framework for building service-oriented applications using .NET
» Replaces ASMX technologies and supports a rich set of service features under a
  unified programming model:
  » RPC style service operations
  » Message style service operations
  » Authentication/Authorization
  » Highly extensible framework
  » Highly configurable framework
  » Flexible hosting options
  » Supports multiple communication protocols
WCF Services – ABC’s
» WCF is complex and has many moving pieces but the key to
    understanding a WCF service is to learn your ABC’s

» Address – Where is the service?
» Binding – How do I talk to the service?
» Contract – What can the service do for me?

»   …A is for address it’s good enough for me, B is for binding it’s good enough for me, C is for contract it’s good enough for me, oh contract-
    contract-contract starts with “C”
                                                                                                                                 C. Monster May 2, 2012
WCF Services – ABC’s Continued
» Address
  » A WCF address uniquely identifies the service.
  » All WCF services are deployed at a specific address, listening at that address for incoming
    requests.
  » Typically expressed as an explicit path or URI with the first part specifying the transport
    mechanism and the hierarchical parts specifying the unique location of the service.

        [transport]://[machine][:optional port]

        http://localhost
        http://localhost:8080
        http://localhost:8080/SomeService
        net.tcp://localhost:8081/SomeService
        net.pipe://localhost/Pipe
WCF Services – ABC’s Continued
» Binding
  »   Bindings are used to specify the transport, encoding and protocol details required for clients and services to communicate with
      each other.
  »   Bindings are what WCF uses to generate the underlying wire representation of the endpoint.

  »   Some common bindings include:
       » BasicHttpBinding:
         » Represents a binding that a service can use to configure and expose endpoints that are able to communicate with ASMX-
            based Web services and clients and other services that conform to the WS-I Basic Profile 1.1.
       » WSHttpBinding:
         » Represents an interoperable binding that supports distributed transactions and secure, reliable sessions.
       » NetTcpBinding:
         » A secure, reliable binding suitable for cross-machine communication. Binary message encoding ensures maximum
            performance.
       » Additional bindings include: BasicHttpContextBinding, BasicHttpContextBinding, WS2007HttpBinding,
         WSHttpContextBinding, WSDualHttpBinding, WebHttpBinding, WS2007FederationHttpBinding, WSFederationHttpBinding,
         NetTcpContextBinding, NetPerrTcpBinding, NetNamedPipeBinding, NetMsmqBinding, MsmqIntegrationBinding

  »   If none of the OOB bindings meet your needs you can roll your own custom binding.
  »   A binding consists of an ordered set of binding elements stacked on top of each other. Each binding element is responsible for
      some aspect of message processing: Encoding, Transport etc.
WCF Services – ABC’s Continued
» Contract
  »   A WCF contract is a platform-neutral and standard way of describing what the service does.
  »   A WCF service communicates with other applications according to its contracts.

  »   There are several types of WCF contracts:
       » Service Contract:
          » Marks an interface as a service contract.
       » Operation Contract:
          » Marks a method on the service contract as being a service method.
       » Data Contract:
          » Marks a type as a data contract for use as parameters or return values.
          » RPC style messaging.




      »   Message Contract:
          » Marks a type as a message contract for user as parameters or return values.
          » Message style messaging.



      »   Fault Contract:
          »  Marks a type as a fault.
          »  Service operations must advertise the types of faults they can throw so clients can more easily respond to service exceptions using
             typed exceptions.
WCF Services – Channel Stack
Building WCF Services
»   RPC Style:
    » Based on data contracts that describe the data to be exchanged between a service and client.
    » Primitive .NET types such as integers and strings will be automatically serialized by the built in Data
       Contract Serializer.
    » User defined complex types must have a data contract defined for them so that they can be serialized
       by WCF.

»   Message Style:
    » Based on message contracts where you want complete control over the structure of the SOAP message:
        » Headers, body elements etc.
    »   Important when interoperability is paramount or security needs to be controlled at the message or
        message part level.
        » Can sign and encrypt header or body elements etc.

    »   Cannot mix data contracts and message contracts in service operations. If you use a message contract
        anywhere in the service operation you must exclusively use message contract:
        » Operation parameters and return values.
Demo 1 – WCF Contracts
» RPC Style Messaging:
  » ServiceContract
  » DataContract
  » DataMember


» Message Style Messaging:
  » MessageContract
  » MessageHeader
  » MessageBodyMember
  » Message/Data Contract Hybrid?
WCF Diagnostics
» WCF provides a rich set of functionalities that can help you monitor the
  different stages of an application’s life.

» Seamless debugging in VS2010

» Message tracing and logging are available to follow activities end-to-end in your
  application.

» Large set of performance counters to help you gauge your application's
  performance.

» Exposes inspection data of a service at runtime through a WCF Windows
  Management Instrumentation (WMI) provider.

» When the application experiences a failure or starts acting improperly, you can
  use the Event Log to see if anything significant has occurred.
Demo 2 – WCF Message Logging
» Configuring WCF Logging:
  » Web/App.config files
  » Configuration Editor (SvcConfigEditor.exe)
» Viewing Service Logs:
  » Service Trace Viewer (SvcTraceViewer.exe)
Hosting WCF Services
» IIS
  »     Traditional way of hosting a web service.
  »     Provides many useful out of the box features including:
         » Process recycling, idle shutdown, process health monitoring, message-based activation, high availability,
            easy manageability and versioning.
  »     Suitable for enterprise situations.



» WAS: Windows Process Activation Services
  »     WAS is the new process activation mechanism for Windows Server 2008 that is also available on Windows
        Vista and Windows 7.
  »     Is part of IIS7, but can be installed and configured separately.
  »     Can be used with any of the available WCF transports, ports and queues.
  »     Applications that use non-HTTP communication protocols can benefit from IIS features like process recycling,
        rapid fail protection and the common configuration systems which were previously available to only HTTP-
        based applications.
  »     Suitable for enterprise situations.
Hosting WCF Services - Continued
» Windows Service Hosting
  »   The WCF service is hosted in a process managed by the operating system.
  »   Provides a limited set of out-of-the-box features to support high availability, easy manageability, versioning
      and deployment scenarios.


» Self Hosting
  »   Service runs as a standalone application and controls its own lifetime:
       » WinForms application
       » Console application
  »   Most flexible and easiest way of hosting a WCF service.
  »   Availability and features are limited.
  »   Not suitable for enterprise situations.
Securing WCF Services
» Authentication
  » Verifying that you are who you say you are!
  » Internally best facilitated using Active Directory:
    » Credentials cached in the users logon process, automatically passed to the service -
       Windows Integrated Security.


  » Externally best facilitated using forms authentication:
    » Not practical to add external users to your Active Directory.
    » Clients responsibility to provide credentials to the service.
Securing WCF Services – Continued
» Authorization
  » Verifying that you are allowed to do what you want to do!


  » Typically facilitated using roles
     » WCF can use .NET declarative security to associate roles with operations:
       » Windows Token Role Provider
         » Internal Active Directory
       » ASP.NET Role Provider
         » Public internet facing
       » Authorization Store Role Provider
         » Roles stored in AD or XML files
Securing WCF Services – Continued
  Transport Level Security
    » Provides Point-To-Point security
    » Does not require that the communicating parties understand XML-level security
        concepts. This can improve the interoperability, for example, when HTTPS is used to
        secure the communication.
    »   Typically faster since it can rely on hardware support for computationally intensive
        encryption operations.
    »   Transport level authentication checks are enforced before the client sends a message
        [Negotiation] so failures can be detected sooner.
    »   Streaming is possible.
    »   Main disadvantage over MLS is that by the time the service has received the message it
        has already been decrypted – If the service is an intermediary service that simply
        forwards the request potentially sensitive data could be exposed or modified on the
        intermediary server.

  »Regarding configuration, the important part is that the client and service
  agree on the encryption mechanism!
Securing WCF Services – Continued
» Message Level Security
     » Provides End-To-End security
     » Uses the WS-Security specification to secure messages. The WS-Security
         specification describes enhancements to SOAP messaging to ensure confidentiality,
         integrity, and authentication at the SOAP message level.
     »   Requires implementation of XML-level security mechanisms and support for WS-
         Security specification. This might affect the interoperability.
     »   Message security differs from transport security by encapsulating the security
         credentials and claims with every message along with any message protection
         (signing or encryption)
     »   Slower than transport level security.
     »   Cannot use message streaming.

  » Regarding configuration, the important part is that the client and
    service agree on the encryption mechanism!
Demo 3 – Hosting/Securing WCF Services
» Hosting a service in IIS7
  » Examining the .svc file
  » Fileless Service Activation
» Hosting a service in WAS
  » netTcpBinding
  » Requiring Windows credentials
  » Turning on message level security
» Declarative service operation security
Consuming WCF Services
» Service Reference
  »   Simplest and most common way to access one or more WCF services.
  »   Functionality provided by the Visual Studio IDE.
  »   Handles the creation the client proxy and required “plumbing”.


» ServiceModel Metadata Utility Tool (svcutil.exe)
  »   Command line tool that can import a service's metadata to generate WCF client code (proxy classes).
  »   Similar to Channel Factory approach except that the interface is inferred from the metadata from your WCF
      service.
  »   Part of the Windows SDK.


» Channel Factory (ChannelFactory<T>)
  »   Used to invoke operations on the service on the fly without generating and using service proxy.
  »   Some knowledge of WCF internals is required.
  »   Allows for more control over service invocation since class can be shared.
Demo 4 – Consuming WCF Services
» Using ChannelFactory<T>
» Accessing service object behaviors
WCF Extensibility
» The Windows Communication Foundation (WCF) application model is
  designed to solve the greater part of the communication requirements of
  any distributed application.
» The WCF extensibility model is intended to support custom scenarios by
  enabling you to modify system behavior at every level, even to the point
  of replacing the entire application model.
WCF Extensibility – Continued
» Application Runtime:
  » Extends the dispatching and the processing of messages for the application.
     Includes:
     »   Security system
     »   Metadata system
     »   Serialization system
     »   Bindings and binding elements (Connect the application with the underlying channel
         system)

» Channel and Channel Runtime:
  » Extends the system that functions at the message level
     » Providing protocol, transport, and encoding support.


» Host Runtime:
  » Extends the relationship of the hosting application domain to the channel
     and application runtime.
Demo – Extending WCF
» Endpoint extensibility walkthrough
» Implementing a custom parameter inspector
WCF Resources
» Beginners Guide to WCF
  »   http://msdn.microsoft.com/en-us/netframework/aa663324.aspx



» WCF Feature Details
  »   http://msdn.microsoft.com/en-us/library/ms733103.aspx



» WCF and Service-Oriented Architectures
  »   http://visualstudiomagazine.com/articles/2011/06/01/pcnet_wcf-and-soa.aspx



» WCF 4.0 Glossary
  »   http://msdn.microsoft.com/en-us/library/dd456781.aspx

More Related Content

PPTX
WCF (Windows Communication Foundation)
PPTX
Windows Communication Foundation (WCF)
PPTX
WCF Introduction
PDF
Wcf development
PPT
PDF
REST, JSON and RSS with WCF 3.5
PPTX
Web service introduction 2
WCF (Windows Communication Foundation)
Windows Communication Foundation (WCF)
WCF Introduction
Wcf development
REST, JSON and RSS with WCF 3.5
Web service introduction 2

What's hot (20)

PPT
PPTX
Windows Communication Foundation (WCF) Service
PPTX
WCF Fundamentals
PDF
Windows Communication Foundation (WCF)
PPTX
10 Tricks and Tips for WCF
PPT
Tulsa Tech Fest2008 Service Oriented Development With Windows Communication F...
PPT
Interoperability and Windows Communication Foundation (WCF) Overview
PPT
WCF And ASMX Web Services
PPTX
WCF for begineers
PPTX
Advancio, Inc. Academy: Web Sevices, WCF & SOAPUI
PDF
Beginning with wcf service
PPT
Basics of WCF and its Security
PPT
introduction to Windows Comunication Foundation
PPT
Wcf architecture overview
PDF
Understanding Web services
PPTX
Introduction to WCF
PPT
Web services, WCF services and Multi Threading with Windows Forms
PDF
Introduction to Service Oriented Architectures, SOAP/WSDL Web Services and RE...
PDF
Java Web Services [1/5]: Introduction to Web Services
PPTX
Windows Communication Foundation (WCF) Best Practices
Windows Communication Foundation (WCF) Service
WCF Fundamentals
Windows Communication Foundation (WCF)
10 Tricks and Tips for WCF
Tulsa Tech Fest2008 Service Oriented Development With Windows Communication F...
Interoperability and Windows Communication Foundation (WCF) Overview
WCF And ASMX Web Services
WCF for begineers
Advancio, Inc. Academy: Web Sevices, WCF & SOAPUI
Beginning with wcf service
Basics of WCF and its Security
introduction to Windows Comunication Foundation
Wcf architecture overview
Understanding Web services
Introduction to WCF
Web services, WCF services and Multi Threading with Windows Forms
Introduction to Service Oriented Architectures, SOAP/WSDL Web Services and RE...
Java Web Services [1/5]: Introduction to Web Services
Windows Communication Foundation (WCF) Best Practices
Ad

Similar to Session 1 Shanon Richards-Exposing Data Using WCF (20)

PPT
WCFPresentation.ppt WCFPresentation.ppt WCFPresentation.ppt
PPT
Dot Net Training Wcf Dot Net35
PPTX
1. WCF Services - Exam 70-487
PPTX
WCjffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff...
DOC
WCF tutorial
PPTX
web programming
PDF
WCF Interview Questions By Scholarhat PDF
PPS
WCF (Windows Communication Foundation_Unit_01)
PPTX
Complete Architecture and Development Guide To Windows Communication Foundati...
DOCX
Top wcf interview questions
PPTX
Windows Communication Foundation
PDF
Advantage of WCF Over Web Services
PPTX
Windows Communication Foundation
PPT
DotNet_WindowsCommunicationFoundation.ppt
PPTX
Web programming
PPTX
Understanding Web Services by software outsourcing company india
PPT
Java web services
PPTX
Application integration framework & Adaptor ppt
PPTX
SOA & WCF
PPTX
Web services
WCFPresentation.ppt WCFPresentation.ppt WCFPresentation.ppt
Dot Net Training Wcf Dot Net35
1. WCF Services - Exam 70-487
WCjffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff...
WCF tutorial
web programming
WCF Interview Questions By Scholarhat PDF
WCF (Windows Communication Foundation_Unit_01)
Complete Architecture and Development Guide To Windows Communication Foundati...
Top wcf interview questions
Windows Communication Foundation
Advantage of WCF Over Web Services
Windows Communication Foundation
DotNet_WindowsCommunicationFoundation.ppt
Web programming
Understanding Web Services by software outsourcing company india
Java web services
Application integration framework & Adaptor ppt
SOA & WCF
Web services
Ad

More from Code Mastery (20)

PPTX
Using SSRS Reports with SSAS Cubes
PDF
Query Tuning for Database Pros & Developers
PDF
Exploring, Visualizing and Presenting Data with Power View
PDF
Building a SSAS Tabular Model Database
PDF
Designer and Developer Collaboration with Visual Studio 2012 and Expression B...
PDF
Build automation best practices
PPTX
Keynote Rockford Lhotka on the Microsoft Development Platftorm
PPTX
Session 5 Systems Integration Architectures: BizTalk VS Windows Workflow Foun...
PPTX
Session 4 Future of BizTalk and the Cloud
PPTX
Session 3c The SF SaaS Framework
PPTX
Session 3b The SF SaaS Framework
PPTX
Session 3a The SF SaaS Framework
PPTX
Session 2 Integrating SharePoint 2010 and Windows Azure
PPTX
Session 1 IaaS, PaaS, SaaS Overview
PDF
Loading a data warehouse using ssis 2012
PDF
Exploring, visualizing and presenting data with power view
PDF
Data Warehouse Design & Dimensional Modeling
PDF
Creating a Tabular Model Using SQL Server 2012 Analysis Services
PPTX
Preparing for Windows 8 and Metro
PPTX
Extending Your Reach using the Cloud and Mobile Devices
Using SSRS Reports with SSAS Cubes
Query Tuning for Database Pros & Developers
Exploring, Visualizing and Presenting Data with Power View
Building a SSAS Tabular Model Database
Designer and Developer Collaboration with Visual Studio 2012 and Expression B...
Build automation best practices
Keynote Rockford Lhotka on the Microsoft Development Platftorm
Session 5 Systems Integration Architectures: BizTalk VS Windows Workflow Foun...
Session 4 Future of BizTalk and the Cloud
Session 3c The SF SaaS Framework
Session 3b The SF SaaS Framework
Session 3a The SF SaaS Framework
Session 2 Integrating SharePoint 2010 and Windows Azure
Session 1 IaaS, PaaS, SaaS Overview
Loading a data warehouse using ssis 2012
Exploring, visualizing and presenting data with power view
Data Warehouse Design & Dimensional Modeling
Creating a Tabular Model Using SQL Server 2012 Analysis Services
Preparing for Windows 8 and Metro
Extending Your Reach using the Cloud and Mobile Devices

Recently uploaded (20)

PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Empathic Computing: Creating Shared Understanding
PDF
Chapter 3 Spatial Domain Image Processing.pdf
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
KodekX | Application Modernization Development
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Approach and Philosophy of On baking technology
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Electronic commerce courselecture one. Pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Machine learning based COVID-19 study performance prediction
PDF
cuic standard and advanced reporting.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PPTX
A Presentation on Artificial Intelligence
“AI and Expert System Decision Support & Business Intelligence Systems”
The Rise and Fall of 3GPP – Time for a Sabbatical?
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Advanced methodologies resolving dimensionality complications for autism neur...
Empathic Computing: Creating Shared Understanding
Chapter 3 Spatial Domain Image Processing.pdf
The AUB Centre for AI in Media Proposal.docx
KodekX | Application Modernization Development
Network Security Unit 5.pdf for BCA BBA.
20250228 LYD VKU AI Blended-Learning.pptx
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Approach and Philosophy of On baking technology
Review of recent advances in non-invasive hemoglobin estimation
Electronic commerce courselecture one. Pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
Machine learning based COVID-19 study performance prediction
cuic standard and advanced reporting.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
CIFDAQ's Market Insight: SEC Turns Pro Crypto
A Presentation on Artificial Intelligence

Session 1 Shanon Richards-Exposing Data Using WCF

  • 1. Exposing Data Using WCF Shannon Richards Associate Principal Consultant Email: shannonr@magenic.com
  • 2. Expectations » Overview of WCF… » This presentation will set the stage for the following presentations… » If you’re new to WCF – I hope you walk away excited about how WCF can fit into your projects! » If you’re experienced with WCF – I hope you pick up on something new! » Patience is a virtue – You will not become a WCF expert overnight!
  • 3. SOA Overview » What is SOA? » Service-oriented architecture… » It is an evolution of distributed computing based on a model of loose coupling and software composition. » The ubiquity of [and almost universal support for] TCP/IP, HTTP and XML technologies have created an environment where interoperability through services is achievable. » Relies on metadata to describe not only the characteristics of services, but also the data that drives them.
  • 4. SOA Overview – Continued
  • 5. SOA Overview – Continued » Why SOA? » The reality of life in modern IT organizations is that infrastructure is heterogeneous across operating systems, applications, system software and application infrastructure… » Allows business to leverage existing investments in applications and infrastructure to satisfy evolving business needs: » Wrap existing functionality with services and expose them for consumption by other applications. » Loose coupling: » Rather than being bound to an operating system, a development platform or a binary API, SOA defines interactions in terms of contracts and protocols. » Ability to more quickly adapt as business process inevitably changes: » Services can be rapidly developed, deployed, refactored and consumed by existing software systems.
  • 6. WCF » What is WCF? » Windows Communication Foundation » Microsoft’s framework for building service-oriented applications using .NET » Replaces ASMX technologies and supports a rich set of service features under a unified programming model: » RPC style service operations » Message style service operations » Authentication/Authorization » Highly extensible framework » Highly configurable framework » Flexible hosting options » Supports multiple communication protocols
  • 7. WCF Services – ABC’s » WCF is complex and has many moving pieces but the key to understanding a WCF service is to learn your ABC’s » Address – Where is the service? » Binding – How do I talk to the service? » Contract – What can the service do for me? » …A is for address it’s good enough for me, B is for binding it’s good enough for me, C is for contract it’s good enough for me, oh contract- contract-contract starts with “C” C. Monster May 2, 2012
  • 8. WCF Services – ABC’s Continued » Address » A WCF address uniquely identifies the service. » All WCF services are deployed at a specific address, listening at that address for incoming requests. » Typically expressed as an explicit path or URI with the first part specifying the transport mechanism and the hierarchical parts specifying the unique location of the service. [transport]://[machine][:optional port] http://localhost http://localhost:8080 http://localhost:8080/SomeService net.tcp://localhost:8081/SomeService net.pipe://localhost/Pipe
  • 9. WCF Services – ABC’s Continued » Binding » Bindings are used to specify the transport, encoding and protocol details required for clients and services to communicate with each other. » Bindings are what WCF uses to generate the underlying wire representation of the endpoint. » Some common bindings include: » BasicHttpBinding: » Represents a binding that a service can use to configure and expose endpoints that are able to communicate with ASMX- based Web services and clients and other services that conform to the WS-I Basic Profile 1.1. » WSHttpBinding: » Represents an interoperable binding that supports distributed transactions and secure, reliable sessions. » NetTcpBinding: » A secure, reliable binding suitable for cross-machine communication. Binary message encoding ensures maximum performance. » Additional bindings include: BasicHttpContextBinding, BasicHttpContextBinding, WS2007HttpBinding, WSHttpContextBinding, WSDualHttpBinding, WebHttpBinding, WS2007FederationHttpBinding, WSFederationHttpBinding, NetTcpContextBinding, NetPerrTcpBinding, NetNamedPipeBinding, NetMsmqBinding, MsmqIntegrationBinding » If none of the OOB bindings meet your needs you can roll your own custom binding. » A binding consists of an ordered set of binding elements stacked on top of each other. Each binding element is responsible for some aspect of message processing: Encoding, Transport etc.
  • 10. WCF Services – ABC’s Continued » Contract » A WCF contract is a platform-neutral and standard way of describing what the service does. » A WCF service communicates with other applications according to its contracts. » There are several types of WCF contracts: » Service Contract: » Marks an interface as a service contract. » Operation Contract: » Marks a method on the service contract as being a service method. » Data Contract: » Marks a type as a data contract for use as parameters or return values. » RPC style messaging. » Message Contract: » Marks a type as a message contract for user as parameters or return values. » Message style messaging. » Fault Contract: » Marks a type as a fault. » Service operations must advertise the types of faults they can throw so clients can more easily respond to service exceptions using typed exceptions.
  • 11. WCF Services – Channel Stack
  • 12. Building WCF Services » RPC Style: » Based on data contracts that describe the data to be exchanged between a service and client. » Primitive .NET types such as integers and strings will be automatically serialized by the built in Data Contract Serializer. » User defined complex types must have a data contract defined for them so that they can be serialized by WCF. » Message Style: » Based on message contracts where you want complete control over the structure of the SOAP message: » Headers, body elements etc. » Important when interoperability is paramount or security needs to be controlled at the message or message part level. » Can sign and encrypt header or body elements etc. » Cannot mix data contracts and message contracts in service operations. If you use a message contract anywhere in the service operation you must exclusively use message contract: » Operation parameters and return values.
  • 13. Demo 1 – WCF Contracts » RPC Style Messaging: » ServiceContract » DataContract » DataMember » Message Style Messaging: » MessageContract » MessageHeader » MessageBodyMember » Message/Data Contract Hybrid?
  • 14. WCF Diagnostics » WCF provides a rich set of functionalities that can help you monitor the different stages of an application’s life. » Seamless debugging in VS2010 » Message tracing and logging are available to follow activities end-to-end in your application. » Large set of performance counters to help you gauge your application's performance. » Exposes inspection data of a service at runtime through a WCF Windows Management Instrumentation (WMI) provider. » When the application experiences a failure or starts acting improperly, you can use the Event Log to see if anything significant has occurred.
  • 15. Demo 2 – WCF Message Logging » Configuring WCF Logging: » Web/App.config files » Configuration Editor (SvcConfigEditor.exe) » Viewing Service Logs: » Service Trace Viewer (SvcTraceViewer.exe)
  • 16. Hosting WCF Services » IIS » Traditional way of hosting a web service. » Provides many useful out of the box features including: » Process recycling, idle shutdown, process health monitoring, message-based activation, high availability, easy manageability and versioning. » Suitable for enterprise situations. » WAS: Windows Process Activation Services » WAS is the new process activation mechanism for Windows Server 2008 that is also available on Windows Vista and Windows 7. » Is part of IIS7, but can be installed and configured separately. » Can be used with any of the available WCF transports, ports and queues. » Applications that use non-HTTP communication protocols can benefit from IIS features like process recycling, rapid fail protection and the common configuration systems which were previously available to only HTTP- based applications. » Suitable for enterprise situations.
  • 17. Hosting WCF Services - Continued » Windows Service Hosting » The WCF service is hosted in a process managed by the operating system. » Provides a limited set of out-of-the-box features to support high availability, easy manageability, versioning and deployment scenarios. » Self Hosting » Service runs as a standalone application and controls its own lifetime: » WinForms application » Console application » Most flexible and easiest way of hosting a WCF service. » Availability and features are limited. » Not suitable for enterprise situations.
  • 18. Securing WCF Services » Authentication » Verifying that you are who you say you are! » Internally best facilitated using Active Directory: » Credentials cached in the users logon process, automatically passed to the service - Windows Integrated Security. » Externally best facilitated using forms authentication: » Not practical to add external users to your Active Directory. » Clients responsibility to provide credentials to the service.
  • 19. Securing WCF Services – Continued » Authorization » Verifying that you are allowed to do what you want to do! » Typically facilitated using roles » WCF can use .NET declarative security to associate roles with operations: » Windows Token Role Provider » Internal Active Directory » ASP.NET Role Provider » Public internet facing » Authorization Store Role Provider » Roles stored in AD or XML files
  • 20. Securing WCF Services – Continued Transport Level Security » Provides Point-To-Point security » Does not require that the communicating parties understand XML-level security concepts. This can improve the interoperability, for example, when HTTPS is used to secure the communication. » Typically faster since it can rely on hardware support for computationally intensive encryption operations. » Transport level authentication checks are enforced before the client sends a message [Negotiation] so failures can be detected sooner. » Streaming is possible. » Main disadvantage over MLS is that by the time the service has received the message it has already been decrypted – If the service is an intermediary service that simply forwards the request potentially sensitive data could be exposed or modified on the intermediary server. »Regarding configuration, the important part is that the client and service agree on the encryption mechanism!
  • 21. Securing WCF Services – Continued » Message Level Security » Provides End-To-End security » Uses the WS-Security specification to secure messages. The WS-Security specification describes enhancements to SOAP messaging to ensure confidentiality, integrity, and authentication at the SOAP message level. » Requires implementation of XML-level security mechanisms and support for WS- Security specification. This might affect the interoperability. » Message security differs from transport security by encapsulating the security credentials and claims with every message along with any message protection (signing or encryption) » Slower than transport level security. » Cannot use message streaming. » Regarding configuration, the important part is that the client and service agree on the encryption mechanism!
  • 22. Demo 3 – Hosting/Securing WCF Services » Hosting a service in IIS7 » Examining the .svc file » Fileless Service Activation » Hosting a service in WAS » netTcpBinding » Requiring Windows credentials » Turning on message level security » Declarative service operation security
  • 23. Consuming WCF Services » Service Reference » Simplest and most common way to access one or more WCF services. » Functionality provided by the Visual Studio IDE. » Handles the creation the client proxy and required “plumbing”. » ServiceModel Metadata Utility Tool (svcutil.exe) » Command line tool that can import a service's metadata to generate WCF client code (proxy classes). » Similar to Channel Factory approach except that the interface is inferred from the metadata from your WCF service. » Part of the Windows SDK. » Channel Factory (ChannelFactory<T>) » Used to invoke operations on the service on the fly without generating and using service proxy. » Some knowledge of WCF internals is required. » Allows for more control over service invocation since class can be shared.
  • 24. Demo 4 – Consuming WCF Services » Using ChannelFactory<T> » Accessing service object behaviors
  • 25. WCF Extensibility » The Windows Communication Foundation (WCF) application model is designed to solve the greater part of the communication requirements of any distributed application. » The WCF extensibility model is intended to support custom scenarios by enabling you to modify system behavior at every level, even to the point of replacing the entire application model.
  • 26. WCF Extensibility – Continued » Application Runtime: » Extends the dispatching and the processing of messages for the application. Includes: » Security system » Metadata system » Serialization system » Bindings and binding elements (Connect the application with the underlying channel system) » Channel and Channel Runtime: » Extends the system that functions at the message level » Providing protocol, transport, and encoding support. » Host Runtime: » Extends the relationship of the hosting application domain to the channel and application runtime.
  • 27. Demo – Extending WCF » Endpoint extensibility walkthrough » Implementing a custom parameter inspector
  • 28. WCF Resources » Beginners Guide to WCF » http://msdn.microsoft.com/en-us/netframework/aa663324.aspx » WCF Feature Details » http://msdn.microsoft.com/en-us/library/ms733103.aspx » WCF and Service-Oriented Architectures » http://visualstudiomagazine.com/articles/2011/06/01/pcnet_wcf-and-soa.aspx » WCF 4.0 Glossary » http://msdn.microsoft.com/en-us/library/dd456781.aspx