+ All Categories
Home > Documents > Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows...

Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows...

Date post: 29-Jun-2020
Category:
Upload: others
View: 5 times
Download: 0 times
Share this document with a friend
122
INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it is still Valid for Enterprise Level Software Concepts and Details of WCF © Johan Lindfors https :// slideplayer .se/slide/2406010/
Transcript
Page 1: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

INNOVATION 2.0

Windows Communication Foundation

■ Enterprise Applications

■ WCF Goals and Reasoning

■ Why it is still Valid for Enterprise Level Software

■ Concepts and Details of WCF

© Johan Lindfors

https://slideplayer.se/slide/2406010/

Page 2: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

2 von 122School of Engineering © K. Rege, ZHAW

Dilemma in the Enterprise IT World

Technology/Know-how is aging Young (&Wild) but not "Enterprise Ready"

scalability

security

replication

… as soonas we get

a tow

Hi! we're the hotopen-source startupwe can help with allof your app container-ization needs

Docker

https://en.wikipedia.org/wiki/OpenVMS https://en.wikipedia.org/wiki/Docker_%28software%29

Page 3: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

3 von 122School of Engineering © K. Rege, ZHAW

Corporate IT World - Bullshit Bingo 2020(D)

Page 4: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

4 von 122School of Engineering © K. Rege, ZHAW

The Challenges ofEnterprise Applications

Development

Page 5: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

5 von 122School of Engineering © K. Rege, ZHAW

Enterprise Application

Initial Problem

Page 6: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

6 von 122School of Engineering © K. Rege, ZHAW

1. Step: Separation of Concern

PersistenzdienstPersistenzdienst

Darstellungs- undInteraktionssteuerung

Darstellungs- undInteraktionssteuerung

KontoKonto VertragVertrag

SicherheitsdienstSicherheitsdienst

TransaktionssteuerungTransaktionssteuerung

KundeKunde

BestellungBestellung

■ Definition of "Entities" with clearly specified Interfaces and Tasks

Konto Übersicht JSFKonto Übersicht JSF

ZustandsverwaltungZustandsverwaltung

Konto DBKonto DB

VerbindungsdienstVerbindungsdienst

DB AdministrationDB Administration

Lebenszyklus-dienst

Lebenszyklus-dienst

Peter Tomczyk

Page 7: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

7 von 122School of Engineering © K. Rege, ZHAW

2. Step: Assignment to Tier-"Role"

PersistenzdienstPersistenzdienst

Darstellungs- undInteraktionssteuerung

Darstellungs- undInteraktionssteuerung

KontoKonto VertragVertrag

SicherheitsdienstSicherheitsdienst

TransaktionssteuerungTransaktionssteuerung

KundeKunde

Datenquellen

BestellungBestellung

Presentation

Logic

■ On which Tier the entity is located: Presentation, Logic, Persistency

Konto Übersicht JSFKonto Übersicht JSF

Persistency

ZustandsverwaltungZustandsverwaltung

Konto DBKonto DB

VerbindungsdienstVerbindungsdienst

DB AdministrationDB Administration

Lebenszyklus-dienst

Lebenszyklus-dienst

Peter Tomczyk

Page 8: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

8 von 122School of Engineering © K. Rege, ZHAW

3. Step: Separation of Shared Services

KontoKonto

VertragVertrag

KundeKunde

BestellungBestellung

ApplicationClient Container

ApplicationContainer

■ Separation of domain specific and domain agnostic parts

SessionVerwatlung

SessionVerwatlung

Presentation- andInteractioncontrol

Presentation- andInteractioncontrolKonto Übersicht JSFKonto Übersicht JSF

technical, domain agnostic -><- domain specific

Konto DBKonto DB DB AdministrationDB Administration

PersistencyContainer z.B.Database

Peter Tomczyk

Persistency ManagementPersistency Management

Security ServiceSecurity Service

Transaction ControlTransaction Control

State ManagementState Management

Directory ServiceDirectory Service

Livecycle ManagementLivecycle Management

Monitoring & ConfigurationMonitoring & Configuration

Page 9: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

9 von 122School of Engineering © K. Rege, ZHAW

Enterprise Architecture

■ Die Architecture describes the responsibilities and interaction of the parts of the

system

Application ServerApplication Server

App ContainerApp ContainerBusiness LogicBusiness Logic

Client / Web ContainerClient / Web Container

Application Server

Client / WebContainer

Client / WebContainer

App Container

Business LogicBusiness Logic

Communication Backbone

Service BusService Bus Data SourcesData Sources

Client LogicClient Logic

http://radar.zhaw.ch/~rege/ea_fs16/ejb1.pdf

Page 10: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

10 von 122School of Engineering © K. Rege, ZHAW

Java Enterprise Edition (JEE)

BrowserClient

BrowserClient HTTP

Application Server

Oracle

Web Containerz.B. Tomcat

Web Containerz.B. Tomcat

MySQL

RMI/IIOPSOAP*

ExistingApplications

BrowserClient

BrowserClient

JSP/JSF*JSP/JSF*

EJB Containerz.B. Glassfish

BusinessLogic

BusinessLogic

ApplicationClient Container

Non-BrowserClient

Non-BrowserClient

"HTTP Interpreter" i.e.Browser

JDBC

z.B. MQ

ApplicationClient Container

Page 11: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

11 von 122School of Engineering © K. Rege, ZHAW

Comparing Azure SF vs. JEE Stack

Azure SF

WCFWCF

ASMX / WSEASMX / WSE

SOAP/otherSOAP/other

Azure Service BusAzure Service Bus

Service FabricService Fabric

RMI

JAX-WS

CORBA

JMS

EJB

JEE

https://docs.microsoft.com/en-us/azure/service-fabric/service-fabric-overview http://radar.zhaw.ch/~rege/ea_fs16/ejb1.pdf

Page 12: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

12 von 122School of Engineering © K. Rege, ZHAW

Future of SOA - probably 2021

■ Cloud Native

■ Core Technologies for Cloud Native■ Docker: Container for Microservice■ Kubernetes: Orchestration of Containers■ gRPC: Communication Protocol

https://dotnet.microsoft.com/learn/aspnet/microservices-architecture

https://docs.microsoft.com/en-us/dotnet/architecture/grpc-for-wcf-developers/

Page 13: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

13 von 122School of Engineering © K. Rege, ZHAW

App Container (EJB or SF)

■ Is the runtime environment of services

■ EJB and WCF are SOA Containers

■ Every "Enterprise Level" SOA Container

has to provide a specific set of 7 services

Persistency ManagementPersistency Management

Security ServiceSecurity Service

Transaction ControlTransaction Control

State ManagementState Management

Directory ServiceDirectory Service

Lifecycle ManagementLifecycle Management

Monitoring & ConfigurationMonitoring & Configuration

Page 14: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

14 von 122School of Engineering © K. Rege, ZHAW

Monitoring & Configuration

■ Monitoring of a System and its resources

at Runtime■ Status Monitoring/System Health Check■ Logging / Tracing (Log across platforms)■ Error Tracking, Diagnosis, Debugging■ Alerts in case of errors■ Performance Analysis -> Indicators for Tuning

■ Configuration of a System and its resources

at runtime■ e.g. Logging/Tracing Level Options etc.

■ Problems■ Number of Systems to monitor■ Different Standards on different levels■ Is done by operations who does not really understand/know the application

Page 15: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

15 von 122School of Engineering © K. Rege, ZHAW

State/Context Management

■ State refers to general condition of something■ a car that is moving is in the state of motion (active)■ a car not moving is in a stationary state (passive)

■ Type of State Information

■ The amount of State to be preserved determines scalability■ the less state the better the scalability

■ Goal Stateless: only state during the active call (no intercall state)

Typical States of EJB Resource

Page 16: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

16 von 122School of Engineering © K. Rege, ZHAW

Livecycle Management

■ An additional State: does not exist

■ To handle system resourceseconomically not all services are

loaded into memory

■ On demand the service is "brought to live"

■ Relevant States in this Context■ Does not exist: In this state, the service instance simply does not exist.■ Ready state: An instance in the ready state is tied to particular client and engaged in a

conversation.■ Passive state: An instance in the passive state is passivated to conserve resource.

Page 17: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

17 von 122School of Engineering © K. Rege, ZHAW

Directory Service

■ A federated database, that handle mainly static data■ data changes are relative rare

■ Typical Products■ LDAP, Active Directory, JNDI

■ Directory for Users■ the users that allowed to access the system■ Names, Credentials, Roles etc.

■ Directory for Resources■ Directory for Hardware and Software Resources■ e.g. Database Resources

■ Directory for (Micro-) Services■ for service discovery also a directory is used■ -> allow for location transparency (serverless computing)

Page 18: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

18 von 122School of Engineering © K. Rege, ZHAW

Security Service

■ Authentication■ User has to be authenticated in a standardized way■ he/she provides Credentials and become a

■ Managed Identity■ An identity in the Directory that is automatically■ Directory also manages the credentials for authenticating .

■ Service Principal■ A security identity used by applications or services to access specific resources/services. You can

think of it as a user identity (username and password or certificate) for an application.

■ Access Control■ Preferably a role based access control schema

■ User■ An individual with a profile in the directory

■ Group■ A set of users created with same roles and rights

■ Required Role to access a service can be defined via Attribute in WCF

[PrincipalPermission(Role = "MarketServiceSuperUser")] public double GetMarketPrice(string symbol)

Page 19: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

19 von 122School of Engineering © K. Rege, ZHAW

Transaction Control

■ Distributed Data■ By design, each microservice encapsulates its own data,

exposing operations via its public interface. If

■ Problem: implement a transaction across multiple services?■ Solution 1: Distributed Transaction

■ Container Managed Transactions: complexity in infrastructure

■ Solution 2: aborts the operation and invokes a compensation operation■ saga Pattern: complexity from a programming point of view

Commit/RollbackStart

Page 20: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

20 von 122School of Engineering © K. Rege, ZHAW

Persistency Management

■ Functionality to facilitate Access to persistent data containers

■ Handling of Connection String■ Is highly sensible: credentials to access all data on database■ Has to be stored, administrated and federated in a secure manner■ e.g. Azure service vault

■ Pooling of established Database Connections■ pooling/reuse of once established db connections

■ Mapping of Relational to Object Oriented form

Page 21: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

21 von 122School of Engineering © K. Rege, ZHAW

WCF

Page 22: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

22 von 122School of Engineering © K. Rege, ZHAW

WCF Goals

■ Was originally invented to replace different technologies■ .NET Remoting■ ASMX: ASP.NET Web Services■ MSMQ■ Web Services Enhancements■ COM+ (DCOM)

■ WCF is - much - more complex compared to ASP.NET Web API i.e. ASMX

■ But offers more features■ reliability, transaction, security

■ If you don't need these features WCF may be the wrong choice

https://www.encodedna.com/wcf/tutorial/comprehensive-wcf-tutorial-for-beginners.htm

https://docs.microsoft.com/en-us/dotnet/framework/wcf/getting-started-tutorial

https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/

Page 23: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

23 von 122School of Engineering © K. Rege, ZHAW

Communication Technologies in WCF

■ WCF is the foundation for a "connected system" in a Microsoft Environment

Page 24: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

24 von 122School of Engineering © K. Rege, ZHAW

What can be learned from WCF

■ Flexible hosting for components and services■ WCF can be hosted in ASP.NET runtime■ Windows Service■ COM+ process■ WPF Application for peer-to peer computing

■ Declarative behavior■ Attributes can be used to define aspects of service

■ Communication Channels■ WCF offers multiple channels to communicate: HTTP, TCP, IPC, custom

■ Security Infrastructure■ Standardized security environment, such as defined in WSE 3.0

■ Extensibility■ .WCF allows for custom channels, formatters and proxies■ may inject functionality inside the message flow

Page 25: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

25 von 122School of Engineering © K. Rege, ZHAW

… What can be learned from WCF

■ Aspects of WCF in an overview

http://www.wcftutorial.net/Introduction-to-WCF.aspx

Page 26: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

26 von 122School of Engineering © K. Rege, ZHAW

■ Unifies today’s distributed technology stacks■ Appropriate for use on-machine, cross machine, and

cross Internet

Microsoft: "The unified programming model for rapidly buildingservice-oriented applications on the Windows platform"

■ Interoperates with applications running on other platforms■ Integrates with Microsoft’s own distributed stacks

UnificationUnification

■ Codifies best practices for building distributedapplications in a service-oriented style and mannerServiceService

OrientationOrientation

Windows Communication Foundation

IntegrationIntegration

Page 27: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

27 von 122School of Engineering © K. Rege, ZHAW

Advantages of WCF over SOAP

■ Interoperability■ SOAP is the preferred protocol for WCF■ but WCF services are also interoperable, with a variety of network protocols such as

■ https, TCP, MSMQ etc.■ Applications or services are designed for distributed environment using a single model.

■ Security and Reliability■ Security is a key element in any SOA, and it is provided in the form of

■ authentication, authorization, confidentiality, integrity and auditingof messages shared between the client and the service.

■ Support also for Plain XML, Ajax and REST■ formats that are no more restricted by SOAP■ share plain XML messages between clients and services■ share also JSON messages via Formatters

Page 28: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

28 von 122School of Engineering © K. Rege, ZHAW

AssurancesAssurances

MessagingMessaging

SOAPSOAP

WS-SecurityWS-Security

MTOMMTOMWS-AddressingWS-Addressing

MetadataMetadata

WS-PolicyWS-Policy

WSDLWSDL

WS-DiscoveryWS-Discovery

UDDIUDDI

WS-MetadataExchange

WS-MetadataExchange

WS-TransferWS-Transfer WS-EnumerationWS-Enumeration WS-EventingWS-Eventing

XML SchemaXML Schema

WS-ReliableMessaging

WS-ReliableMessaging WS-CoordinationWS-Coordination

WS-AtomicTransaction

WS-AtomicTransaction

WS-BusinessActivity

WS-BusinessActivity

WS-TrustWS-Trust

WS-SecurityPolicy

WS-SecurityPolicy

Infrastructureand Profiles

Infrastructureand ProfilesWS-ManagementWS-ManagementWS-FederationWS-Federation Devices

Profile

DevicesProfile

FoundationFoundation

SOAP / HTTPSOAP / HTTP

SOAP / UDPSOAP / UDP

MIMEMIME

XML InfosetXML Infoset

XML 1.0XML 1.0 XMLNamespaces

XMLNamespaces

Step 4 – Approved StandardStep 4 – Approved Standard

Step 3 – StandardizationStep 3 – Standardization

Step 2 – Workshops & Community DevStep 2 – Workshops & Community Dev

WS-* (W3C/OASIS)

SOAP Specification (2018)

https://www.oasis-open.org/committees/tc_home.php?wg_abbrev=wss

http://radar.zhaw.ch/~rege/xml_hs11/soap_v7.pdf

Page 29: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

29 von 122School of Engineering © K. Rege, ZHAW

Hello WCF

http://dotnetpattern.com/hello-world-wcf

Page 30: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

30 von 122School of Engineering © K. Rege, ZHAW

1. Declare ServiceContract

■ Console Solution and name the solution

as "LibraryServiceSolution".■ rem: we do not use WCF Project types because we

want it to do step by step

■ Add a new Interface name "ILibraryService" and follow below steps.■ Add a reference to "System.ServiceModel" assembly. System.ServiceModel assembly is the base

assembly of WCF Service.■ Add the "System.ServiceModel" namespace in the namespaces section.■ Add the [ServiceContract] attribute above

the interface ILibraryService.■ ServiceContract attribute describes that

this interface contains the methodssignatures of WCF service.

■ Add method signature"Book SearchBook(string bookName)" into the interface.

■ Add the attribute [OperationContract] onthe method.

■ attribute describes that this method isincluded in WCF service

using System;using System.ServiceModel;

namespace LibraryServiceSolution { [ServiceContract] interface ILibraryService { [OperationContract] Book SearchBook(string bookName); }}

Page 31: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

31 von 122School of Engineering © K. Rege, ZHAW

2. Declare Data Contract

■ In WCF, data contract is used for serializing custom data types.

In the interface, We are returning the custom type "Book" as a result of"SearchBook" method.

■ Create a new class name "Book"■ Add a reference to "System.Runtime.Serialization" assembly.■ Add the namespace "System.Runtime.Serialization" to the namespaces section.■ Add the [DataContract] attribute above the

class "Book".■ DataContract attribute specifies that this

class is used in WCF service■ Add a new property "ID" of data type int in

class "Book".■ Add the attribute [DataMember] to "ID" property.

■ DataMember attribute specifies that thisproperty is part of data contract.

■ Add a new property "Name" of data type stringin class "Book".

■ Add the attribute [DataMember] to "Name" property.

using System;using System.Runtime.Serialization;

namespace LibraryServiceSolution{ [DataContract] class Book { [DataMember] public int ID { get; set; } [DataMember] public string Name { get; set; } }}

Page 32: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

32 von 122School of Engineering © K. Rege, ZHAW

3. Implement Service

■ Create a new class name "LibraryService" and follow below steps:■ Inherit from interface "ILibraryService"■ Implement the method "SearchBook"

using System;using System.Collections.Generic;

namespace LibraryServiceSolution { class LibraryService : ILibraryService { private List<Book> books; public LibraryService(){ books = new List<Book>(); for (int i = 0; i < 20; ++i){ books.Add(new Book { ID = i, Name = "Name " + i }); } }

public Book SearchBook(string bookName) { return books.Find(w => w.Name == bookName); } }}

Page 33: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

33 von 122School of Engineering © K. Rege, ZHAW

4. Configure Service

■ An endpoint is the defined by an "App.config" file■ Address defines the location of the service■ Binding in simple terms specify the transport protocol of the service.■ Contract list the operations of the service which we already defined in the "ILibraryService" interface<?xml version="1.0" encoding="utf-8" ?><configuration> <system.serviceModel> <services> <service name="LibraryServiceSolution.LibraryService" behaviorConfiguration="LibraryServiceBehavior"> <host> <baseAddresses> <add baseAddress="http://localhost:9999/LibraryService" /> </baseAddresses> </host> <endpoint address="" binding="basicHttpBinding" contract="LibraryServiceSolution.ILibraryService" /> </service> </services> <behaviors> <serviceBehaviors> <behavior name="LibraryServiceBehavior"> <serviceMetadata httpGetEnabled="true" /> </behavior> </serviceBehaviors> </behaviors> </system.serviceModel></configuration>

name: class of the service implementation.behaviorConfiguration: see below

the metadata of our service

base addresses of our LibraryService

endpoint, containing address, binding and contract.Address is blank, so, our final WCF service addressis "http://localhost:9999/LibraryService" + ""

Page 34: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

34 von 122School of Engineering © K. Rege, ZHAW

5. Host Service

■ For hosting the service, we use the "ServiceHost" class.■ We need to pass type information of our "LibraryService" service and call the open method.

■ Run the program as Console Program:■ not in VS because we need it for building the client■ run the program from with administrator permissions

using System;using System.ServiceModel;

namespace LibraryServiceSolution { class Program { static void Main(string[] args){ ServiceHost server = new ServiceHost(typeof(LibraryService)); server.Open(); Console.WriteLine("Your service is started..."); Console.ReadLine(); server.Close();

} }}

C:\Users\Karl Rege\source\repos\LibraryServiceSolution\LibraryServiceSolution\bin\Debug\LibraryServiceSolution.exe

Page 35: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

35 von 122School of Engineering © K. Rege, ZHAW

6. Access Client

■ To check whether service is running

■ Enter url of the service address http://localhost:9999/LibraryService in Browser

Page 36: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

36 von 122School of Engineering © K. Rege, ZHAW

7. Create Client Program

■ New Console Project and name the Project e.g. "ConsoleApplication1"

■ Add a Service Reference with NameSpace LibraryServiceSolution

Page 37: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

37 von 122School of Engineering © K. Rege, ZHAW

8. Implement Client Program

■ Create an instance of "LibraryServiceClient" class.

■ Call the SearchBook method.

using System;using ConsoleApplication1.LibraryServiceSolution;

namespace ConsoleApplication1{ class Program { static void Main(string[] args) { LibraryServiceClient client = new LibraryServiceClient(); Book book = client.SearchBook("Name 12"); Console.WriteLine("Book ID : " + book.ID); Console.ReadLine(); } }}

Congratulation, your firstWCF Service

Page 38: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

38 von 122School of Engineering © K. Rege, ZHAW

WCF Architecture

Page 39: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

39 von 122School of Engineering © K. Rege, ZHAW

WCF Architecture Layers

■ Contract■ define interface of service

■ Runtime■ define runtime behavior

■ Messaging■ define properties of the Messaging

channel

■ Hosting and Activation■ Type of Host■ When Service is activated

Windows Communication Foundation is a multi-layered architecture thatprovides developers with a rich set of functionality.

Page 40: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

40 von 122School of Engineering © K. Rege, ZHAW

Contracts

Page 41: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

41 von 122School of Engineering © K. Rege, ZHAW

Contract First Design

■ Contract first design■ first: design the service contract in terms of the data, messages, and interface it will expose

■ Usually these contracts are called "IDL"■ second: generate the service interface code from the contract■ From there, you can implement the code behind the service interface that performs the processing

required.

■ Advantage: This allows you to concentrate on the format of the messages and

the data types they use at the beginning of the process to maximizeinteroperability and compatibility.

If technology has to be changed, these contracts can be transcribed

■ SOAP however has suffered from a unreadable contract format: WDSL and XSD.

■ Contract First requires comprehensible contract format -> WCF does

e.g. CICS-> CORBA->RMI/IIOP->SOAPe.g. CICS-> CORBA->RMI/IIOP->SOAP

Page 42: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

42 von 122School of Engineering © K. Rege, ZHAW

■ Code First: Avoid

■ Contract First: do it

[ServiceContract]public class OrderEntry { [OperationContract(IsOneWay = true)] public void PlaceOrder(PurchaseOrder order) { return; }}

Programming of Contract

[ServiceContract]public interface IOrderEntry { [OperationContract(IsOneWay = true)] void PlaceOrder(PurchaseOrder order);}public class OrderEntry : IOrderEntry { public void PlaceOrder(PurchaseOrder order) { return; }}

Page 43: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

43 von 122School of Engineering © K. Rege, ZHAW

WCF Contract Types

■ WCF contracts define what service and operations would it provide to the clients■ exchange messages■ provided services■ optionally

■ decides if a transaction is required■ security and access constraints

■ Can defined in any .NET Language; C# is preferred■ Attributed C# Interfaces are used for contract specification

■ Structural Contracts■ DataContract

■ Behavioral Contracts■ ServiceContract■ OperationContract■ FaultContract

Page 44: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

44 von 122School of Engineering © K. Rege, ZHAW

■ Every Field that is Attributed as DataMember is serialized i.e. transferred

■ Not same contract is defined on client and server■ With Name Attribut data to each other as long as the data contracts are equivalent on both

sides:a mechanism is provided to map types and members to those names.

DataContract

using System.Runtime.Serialization;[DataContract(Name="PersonType")]public class Person {

[DataMember]public string name;[DataMember(Name="AgeProperty")]private int age;

[DataMember]float salary;

}

[DataContract]public class PersonType { [DataMember] public string name;

[DataMember] public string AgeProperty;}

Page 45: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

45 von 122School of Engineering © K. Rege, ZHAW

■ Collections may have different Element Types■ KnowType: the types that should be included for consideration during deserialization.

… DataContract

[DataContract][KnownType(typeof(Book))][KnownType(typeof(Magazine))]public class LibraryCatalog{

[DataMember]System.Collections.Hashtable catalog;

}

[DataContract]public class Book{…}[DataContract]public class Magazine{…}

Page 46: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

46 von 122School of Engineering © K. Rege, ZHAW

■ For a new Version additional optional fields may be added

… DataContract Versioning - non Breaking

[DataContract]public class Car { [DataMember(IsRequired = true)] public string Model; [DataMember(IsRequired = false)] //default public int HorsePower;}

Page 47: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

47 von 122School of Engineering © K. Rege, ZHAW

■ Version management, planed in advance

... DataContract Versioning - non Breaking

[DataContract]public class Person : IExtensibleDataObject { public virtual ExtensionDataObject UnknownData { get { return this.unknownData; } set { this.unknownData = value; } }

[DataMember] public string fullName;

private ExtensionDataObject unknownData;}

Page 48: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

48 von 122School of Engineering © K. Rege, ZHAW

... DataContract Versioning - Breaking

■ If breaking changes are immanent, NameSpace should be changed

[DataContract NameSpace="http://www.zhaw/Service/1.0"]public class Car { [DataMember] public string Model; [DataMember] public int HorsePower;}

[DataContract NameSpace="http://www.zhaw/Service/1.1"]]public class Car { [DataMember] public string Model; [DataMember] public int Watt;}

Page 49: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

49 von 122School of Engineering © K. Rege, ZHAW

■ Defines the names of the Service(-Interfaces)

■ Controls how structural contract is serialized■ e.g. define SOAP Formatting Style

ServiceContract

[ServiceContract][DataContractFormat( Style=OperationFormatStyle.Document)] //Or Rpcpublic interface IOrderEntry {...}

[ServiceContract][XmlSerializerFormat( Style=OperationFormatStyle.Document, Use=OperationFormatUse.Literal)] //Or Encodedpublic interface IOrderEntry {...}

Page 50: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

50 von 122School of Engineering © K. Rege, ZHAW

■ Used also for versioning e.g. Non-Breaking simply by Extending Interface■ NameSpace defines also WSDL PortType■ New NameSpace -> Breaking Changes

ServiceContract - Versioning

[ServiceContract NameSpace="http://www.zhaw/Service/1.0"]public interface IOrderEntry{ [OperationContract(IsOneWay = true)] void PlaceOrder(PurchaseOrder order);}

[ServiceContract]public interface IExtendedOrderEntry : IOrderEntry{ [OperationContract] PurchaseOrder GetOrder(String orderIdentifier);}

Page 51: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

51 von 122School of Engineering © K. Rege, ZHAW

■ Implementation■ An implementation of an interface■ Naming Convention: The class is usually called "...Service"

ServiceContract - Implementation

[ServiceContract]public interface IOrderEntry { [OperationContract(IsOneWay = true)] void PlaceOrder(PurchaseOrder order);}

internal class OrderEntryService : IOrderEntry { void IOrderEntry.PlaceOrder(PurchaseOrder order) { //Your code goes here }}

Page 52: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

52 von 122School of Engineering © K. Rege, ZHAW

Operation Contract

■ The operation contract attribute under the service contract defines various

characteristic of the message. Characteristics such as■ a) The data type of the message■ b) Whether the method returns any value or it is a one-way operation■ c) etc.

[ServiceContract]public interface IBook{

[OperationContract()]string BookPrice(string sBookName);[OperationContract()]BookDetails GetBookDetails(string sBookName);

}

Page 53: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

53 von 122School of Engineering © K. Rege, ZHAW

[OperationContract(IsOneWay = true)]void Chat(Message request);

[OperationContract]Message Chat(Message request);

[OperationContract(AsyncPattern=true)]IAsyncResult BeginChat(Message request, AsyncCallback cb, object state);

Message EndChat(IAsyncResult call);

… Operation Contract

Message Exchanges Pattern

■ One-way messages modeled using OneWay=true operation contracts

■ Correlated Request/Reply modeled either as synchronous method

■ or using IAsyncResult pattern

Page 54: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

54 von 122School of Engineering © K. Rege, ZHAW

■ Map to SOAP Action Property■ SOAPAction HTTP request header field can be used to indicate the intent of the SOAP HTTP

request, see http://www.w3.org/TR/2000/NOTE-SOAP-20000508/#_Toc478383528■ only one service operation: the Action property set to "*".

■ can also be used as fallback for wrong action defined in message

■ Action property is used to control the action of the method's input message■ action is used to dispatch an incoming message to the appropriate method

… Operation Contract

[ServiceContract]public interface IOrderEntry {[OperationContract( Action="http://contoso.com/GetOrder", ReplyAction="http://contoso.com/GetOrderReply")] PurchaseOrder GetOrder(String orderIdentifier); [OperationContract(IsOneWay = true, Action="*")] void ProcessUnrecognizedMessage(Message message);}

Page 55: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

55 von 122School of Engineering © K. Rege, ZHAW

FaultContract

[DataContract]class MyFault { [DataMember] public string Reason = null;}[ServiceContract]public interface IOrderEntry { [OperationContract] [FaultContract(typeof(MyFault))] PurchaseOrder GetOrder(String orderId);}public class OrderEntry: IOrderEntry { public PurchaseOrder GetOrder(string orderId) { try{…}

catch(Exception exception) { MyFault theFault = new MyFault(); theFault.Reason = "Some Reason"; throw new FaultException<MyFault>(theFault); }

}}

■ The FaultContract defines what should be done in case of an Error->Exeption

Page 56: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

56 von 122School of Engineering © K. Rege, ZHAW

WCF and WSDL

■ Fine grained control of (generated) WSDL by WCF Attributes

■ <wsdl:definitions>■ <wsdl:portType.../>

■ <wsdl:binding.../>

■ <wsdl:service.../>

<endpoint name="MyServiceEndpoint" bindingNamespace="http://myservice.com/binding"

[ServiceContract(Namespace="urn:gadgets-org")]public interface MyServiceContract {}

[ServiceBehavior(Namespace="urn:my-unique-namespace2")]public class MyService : IMyService

Page 57: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

57 von 122School of Engineering © K. Rege, ZHAW

Summary Contract Features

■ Service and Operation Contracts■ Duplex, Sessionful MEPs■ One-Way, Request-Reply, First/Last Operation, Faults

■ Message and Data Contracts■ Message Schema■ Schema Versioning■ Fine-grained Message Control

■ Action, Direction, Headers, Body, Wrapped/Bare, RPC/Doc, Literal/Encoded

■ Later: Selected sets of features are packaged together to so called "Bindings"

Page 58: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

58 von 122School of Engineering © K. Rege, ZHAW

New InstanceConcurrency

Page 59: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

59 von 122School of Engineering © K. Rege, ZHAW

■ .PerCall■ A new Instance for each call

■ .PerSession, .Shareable■ a new Instance per Session

■ .Single■ a single Instance per Server

Live Cycle: New Instance

[ServiceContract] public interface IEcho{ … }

[ServiceBehavior(InstanceContextMode= InstanceContextMode.Single)]internal class MyService: IEcho { …}

Page 60: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

60 von 122School of Engineering © K. Rege, ZHAW

■ .Single■ With additional constructors

Instantiation

[ServiceContract]public interface IEcho{ ... }

[ServiceBehavior(InstanceContextMode=InstanceContextMode.Single)]internal class MyService: IEcho { private string myData = null; private MyService(){} internal MyService(string startUpData){ this.myData=startUpData; } ...}

public class MyHost { MyService service = new MyService("The initial data"); using(ServiceHost host = new ServiceHost(service)) { ... }}

Page 61: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

61 von 122School of Engineering © K. Rege, ZHAW

■ .PerSession

Instantiation

[ServiceContract][ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]public class Math { private long sum = 0;

[OperationContract] public int Add(int i, int j){ this.sum = this.sum + i + j; return i + j; } [OperationContract] public long GetTotal() { return this.sum; }

[OperationContract] [OperationBehavior(ReleaseInstanceMode = ReleaseInstanceMode.AfterCall)] public void Clear() { this.sum = 0; }}

Page 62: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

62 von 122School of Engineering © K. Rege, ZHAW

■ Concurrency can be one of three modes■ Single (which is the default setting)■ Multiple■ Reentrant

■ Not relevant for instances per call

Concurrency

[ServiceContract]public interface IEchoContract { ... }

[ServiceBehavior(ConcurrencyMode= ConcurrencyMode.Multiple)]public class EchoService: IEchoContract { ... }

Page 63: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

63 von 122School of Engineering © K. Rege, ZHAW

■ Can be used to limit load■ Simultaneous calls, instances, connections

■ Use Case: Server/Infrastructure crashes or degrades if load exceeds a certainlevel

■ Throttling becomes to the only viable option

Throttling

<behaviors> <behavior> <throttling maxConcurrentCalls="2" maxConnections="10" maxInstances="10"/> </behavior></behaviors>

[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple)]public class MyService { ... }

Page 64: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

64 von 122School of Engineering © K. Rege, ZHAW

TransactionControl

Page 65: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

65 von 122School of Engineering © K. Rege, ZHAW

Transaction Control

■ Atomic or compensatory■ Choose between linking or complexity

■ Atomic transactions■ Easier to develop

■ More complex infrastructure

■ Negative impact on performance

■ "Tighter" coupling

■ Compensatory activity (not covered here)■ so called Saga Pattern

■ More more complex to develop

■ Better performance "Looser" coupling

■ Choose model based on the situation

Page 66: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

66 von 122School of Engineering © K. Rege, ZHAW Container

Atomic Transaction Control for SOA

■ Problem 1: "Nested Transaction": A service may call another transactional

service, that needs transaction (begin end)

■ This service may even be remote

■ Semantic and implementation of nested transaction is highly complex

■ Problem 2: If transaction is started on the client side, if the connection is lost or

client dies, then we have orphan/open hanging transactions

Container

begin…commit

begin…commit

Container

begin…commit

begin…commit …

-> BMTD nur in Ausnahmefällenverwenden (Anfänger am bestengar nicht)

-> BMTD nur in Ausnahmefällenverwenden (Anfänger am bestengar nicht)

Page 67: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

67 von 122School of Engineering © K. Rege, ZHAW

Solution Container Managed Transactions

■ Container takes care of transaction demarcation■ Transaction is started when needed■ Container also handles error cases, e.g. rollback when needed

■ To control the behavior of the container, the service describes its transactional

requirement/demands

■ E.g. Transaction Required:■ When calling a service that requires a transaction a new transaciton is started■ if this service calls other (transactional) services the now existing transaction context is passed■ when the original service returns (and no error occurred) the transaction is committed.

Service Call Servicebegin

commitClient

Container

Service Call

Page 68: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

68 von 122School of Engineering © K. Rege, ZHAW

[ServiceContract]public interface IMyContract{ [OperationContract] [TransactionFlow(TransactionFlowOption.Required)] bool Transfer1(Account from, Account to, decimal amount);

[OperationContract] [TransactionFlow(TransactionFlowOption.NotAllowed)] bool Transfer2(Account from, Account to, decimal amount);

}

… Transaction Control

■ Participate in a transaction

Page 69: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

69 von 122School of Engineering © K. Rege, ZHAW

… Transaction Control

■ Developer of the Server■ Transaction completion is controlled by the Server (when Service returns)

■ Transaction completion is controlled by the Application/Service

public class MyService: IMyContract{ [OperationBehavior( TransactionScopeRequired = true, TransactionAutoComplete = true)] public bool Transfer1( Account from, Account to, decimal amount) { ... }

[OperationBehavior( TransactionScopeRequired = true, TransactionAutoComplete = false)] public bool Transfer2( Account from, Account to, decimal amount) { ... OperationContext.Current.SetTransactionComplete(); }}

Page 70: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

70 von 122School of Engineering © K. Rege, ZHAW

… Transaction Control

■ Use Transactions■ client side

TransactionScope transaction;

using (scope = new TransactionScope()){ proxyOne.Transfer1(AccountOne, AccountTwo, amount); proxyTwo.Transfer1(AccountThree,AccountFour,amount); UpdateLocalCache(AccountOne, AccountTwo, amount); scope.Complete();}

Page 71: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

71 von 122School of Engineering © K. Rege, ZHAW

… Transaction Control

■ Control of transactions■ Container/Server managed Transation

<bindings> <wsHttpBinding> <binding name="SampleBinding" transactionFlow="true" /> </binding> </wsHttpBinding></bindings>

Page 72: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

72 von 122School of Engineering © K. Rege, ZHAW

Monitoring/Logging

Page 73: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

73 von 122School of Engineering © K. Rege, ZHAW

Monitoring

■ Several Features may be enabled

by configuration■ Logging/Tracing■ Tracing■ Performance Counters■ Event Logging■ WMI

■ Log Level i.e amount of logged Data mayalso be configured

■ Sources■ System.Security.Authorization■ Microsoft.InfoCards.Diagnostics■ System.IO.Log■ System.Runtime.Serialization■ System.ServiceModel■ Microsoft.TransactionsBridgs.Dtc

■ Levels■ All, Off■ Critical, Error, Warning■ Information, Verbose■ ActivityTracing

Page 74: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

74 von 122School of Engineering © K. Rege, ZHAW

Logging/Tracing

<system.serviceModel> <diagnostics> <messageLogging logEntireMessage="true" maxMessagesToLog="300" logMessagesAtServiceLevel="true" logMalformedMessages="true" logMessagesAtTransportLevel="false" /> </diagnostics></system.serviceModel><system.diagnostics> <sources> <source name="System.ServiceModel.MessageLogging"> <listeners> <add name="MyListener" type="System.Diagnostics.XmlWriterTraceListener" initializeData="C:\logs\Clientraces.e2e" traceOutputOptions="None" /> </listeners> </source> </sources></system.diagnostics>

■ Login is simply enabled by configuration

Page 75: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

75 von 122School of Engineering © K. Rege, ZHAW

■ Turn on counters per service■ Can also be put into machine.config

■ Can be analyzed on four levels■ ServiceHost■ Endpoint■ Operation■ (AppDomain)

■ Displayed by Performance

Monitor

<configuration> <system.serviceModel> <diagnostics performanceCountersEnabled="true"/> </system.serviceModel></configuration>

Performance Counters

Page 76: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

76 von 122School of Engineering © K. Rege, ZHAW

Encoding

Page 77: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

77 von 122School of Engineering © K. Rege, ZHAW

Encoding - Data Format "on the Wire"

■ Text■ For best interoperability

■ Binary■ For best performance WCF to WCF

■ MTOM■ Message Transmission Optimization Protocol■ To attach binary extensions■ Uses XML-binary Optimized Packaging

<bindings> <wsHttpBinding> <binding name="MTOMBinding" messageEncoding="Mtom"/> </wsHttpBinding></bindings>

Page 78: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

78 von 122School of Engineering © K. Rege, ZHAW

Address

Page 79: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

79 von 122School of Engineering © K. Rege, ZHAW

Address

■ When a client wants to have access to a WCF service, it needs to locate the

actual location of the service.

■ An address is the endpoint location that provides the service to the outer worldespecially its clients using a network protocol.

■ The address is usually in the form of an URL.

■ A typical URL would have these elements defined with specific values.■ a) Protocol: The transport protocol used to transfer data (messages) from one location to another.

Protocols such as, https or HTTPs ("s" stands for "secure").■ b) Location and Port: The location of the service and the port number where the service is running

■ Eg: "//localhost:1995" - A locally hosted service using "localhost" and a port number "1995".■ c) Path and Service: The actual path and name of service, which is running

http://x.se:80/Service/MyEndPointnet.tcp://x.se:8080/Service/MyEndPointnet.pipe://x.se/Service/MyEndPointnet.msmq://x.se/MyQueue

Page 80: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

80 von 122School of Engineering © K. Rege, ZHAW

Server Address

■ Per Server by Code■ One base address per mode of transport

■ Per "Endpoint" via Configuration■ The address is relative to the base address (of the machine)

class Program { static void Main(string[] args) { using (ServiceHost host = new ServiceHost( typeof(EchoService), new Uri("http://localhost:8000/EchoService"))) { host.Open(); Console.ReadLine(); host.Close();} } }

<service name="EchoService"> <endpoint address="Echo" binding="basicHttpBinding" contract="IEcho"/></service>

Page 81: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

81 von 122School of Engineering © K. Rege, ZHAW

Client Address

■ With code and Configurationusing System.ServiceModel;namespace MyNamespace { public interface IEcho { string Echo(string input); }

public class Program { public static void Main(string[] arguments) { IEcho proxy = new ChannelFactory<IEcho> ("EchoService").CreateChannel(); Console.WriteLine(proxy.Echo("Ping")); ((IChannel)proxy).Close(); } }}

<system.serviceModel> <client> <endpoint name="EchoService" address="http://localhost:8000/EchoService/Echo" binding="basicHttpBinding" contract="MyNamespace.IEcho"/> </client></system.serviceModel>

Page 82: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

82 von 122School of Engineering © K. Rege, ZHAW

Binding

Page 83: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

83 von 122School of Engineering © K. Rege, ZHAW

Binding

■ WCF bindings represent a collection of elements, which will describe the various

aspects of communication between a service and its clients.

■ Its three main characteristics are,

■ 1) What protocol it shall use for the communication?■ An optional feature, a protocol defines information related to security, reliability and transaction flow

of the message.

■ 2) How does it transport the message?■ It will define the means for transporting message from service endpoint to a client endpoint. The

transport you may use can either be an https, HTTPs, TCP and MSMQ etc.

■ 3) Do we need to encode the message?■ This feature is required to specify the encoding of the message, which can be either a Text or

Binary message. The default message encoder is XML or Text for https and HTTPs transports,binary message encoder for other transports.

■ WCF provides many different types of pre-defined bindings

Page 84: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

84 von 122School of Engineering © K. Rege, ZHAW

Inside Bindings

TransportTransport

IPCMSMQ

Custom

TCP HTTP

ProtocolProtocolEncodersEncoders

MTOMMTOM

TextText

CustomCustom

.NETTX

Custom

Security RM

BindingBindingHTTP TextText TXSecurity RM

BinaryBinary

Page 85: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

85 von 122School of Engineering © K. Rege, ZHAW

WCF Defines 9 Standard Bindings

■ Basic binding■ designed to expose a WCF service as a legacy ASMX web service, so that old clients can work■ To be preferred if compatibility is key requirement

■ Web Service (WS) binding■ this uses HTTP or HTTPS for transport,■ offers a variety of features such as reliability, transactions, and security over the Internet.

■ TCP binding■ uses TCP for cross-machine communication on the intranet.■ It supports a variety of features, including reliability, transactions, and security, and is optimized for

WCF-to-WCF communication. it requires both the client and the service to use WCF.

■ Peer network binding■ The peer network-enabled client and services all subscribe to the same grid and broadcast

messages to it.

■ IPC binding■ Uses named pipes as a transport for same-machine communication.

Page 86: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

86 von 122School of Engineering © K. Rege, ZHAW

WCF Defines 9 Standard Bindings

■ Federated WS binding■ a specialization of the WS binding, offering support for federated security.

■ Duplex WS binding■ similar to the WS binding except it also supports bidirectional communication from the service to

the client.

■ MSMQ binding■ uses MSMQ for transport and is designed to offer support for disconnected queued calls.

■ MSMQ integration binding■ to interoperate with legacy MSMQ clients. Using this binding is beyond the scope of this book.

Page 87: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

87 von 122School of Engineering © K. Rege, ZHAW

Binding Features

■ Bindings have semantics■ Session, Duplex, Transaction Flow, ..

■ Asserting Semantic Requirements in Code

■ Features■ Encoding

■ Text, Binary, Custom■ Transport selection

■ TCP, HTTP, Named Pipes, P2P, MSMQ, Custom■ End-to-end Security

■ Confidentiality, integrity, authN, authZ, federation■ Credentials: X509, User/Pwd, Kerberos, SAML, InfoCard, Custom

■ End-to-end Reliable messaging■ Transport independent QoS (in order, exactly once)■ Volatile and durable queues for availability

■ Transactions■ Shared transactions for "synchronous" operations■ Transactional queues for "asynchronous" operations

Page 88: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

88 von 122School of Engineering © K. Rege, ZHAW

Interop

Security

Session

Transactions

Duplex

Stream

ing

BasicHttpBinding BP 1.1 T O

WsHttpBinding WS T | S X X O

WsDualHttpBinding WS T | S X X X O

NetTcpBinding .NET T | S X X X O

NetNamedPipesBinding .NET T | S X X X O

NetMsmqBinding .NET T | S X X

NetPeerTcpBinding .NET T | S X

T = Transport Security | S = WS-Security | O = One-Way Only

Protocoll Features and Standard Bindings

Page 89: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

89 von 122School of Engineering © K. Rege, ZHAW

BasicHttpBindingBasicHttpBinding

WsHttpBindingWsHttpBinding

WhatLevel

?

Duplex?

WsDualHttpBindingWsDualHttpBinding

NetNamedPipeBinding

NetNamedPipeBinding

NetMsmqBindingNetMsmqBinding

NetPeerTcpBindingNetPeerTcpBinding

NetTcpBindingNetTcpBinding

NoNo

BasicBasic

NoNo

YesYes

Local?

NeedQueues

?

Peerto

Peer?

NoNo

NoNo

NoNo

YesYes

YesYes

YesYes

WS-*WS-*

YesYes

Which Binding To Use When?

Interop

Page 90: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

90 von 122School of Engineering © K. Rege, ZHAW

ASMX/WSE3ASMX/WSE3 WCFWCF

WCFWCF ASMX/WSE3ASMX/WSE3

MSMQMSMQ WCFWCF

WCFWCF MSMQMSMQ

WS-* Protocols

WS-* Protocols

MSMQ Protocol

MSMQ Protocol

MSMQBinding

MSMQBinding

Http/WS

Binding

Http/WSBinding

JavaJava WCFWCF

WCFWCF JavaJava

WS-* Protocols

WS-* Protocols

Http/WS

Binding

Http/WSBinding

WCFWCF WCFWCFWS-* Protocols*

Binding

*Binding*

Binding

*Binding

COM(+)COM(+) WCFWCF

WCFWCF COM+COM+

WS-* Protocols

WS-* Protocols

Moniker

‘Stub’

Which Binding To Use When?

Page 91: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

91 von 122School of Engineering © K. Rege, ZHAW

BindingConfiguration

Page 92: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

92 von 122School of Engineering © K. Rege, ZHAW

Bindings: Select one Standard Binding

<?xml version="1.0" encoding="utf-8" ?><configuration> <system.serviceModel> <services> <service name="MathService"> <endpoint address="http://localhost/MathEndpoint" binding="wsHttpBinding" contract="IMathService" /> </service> </services> </system.serviceModel></configuration>

Page 93: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

93 von 122School of Engineering © K. Rege, ZHAW

Bindings: Adjusted

<configuration> <system.serviceModel> <services> <service name="MathService"> <endpoint address="http://localhost/MathEndpoint" binding="wsHttpBinding" bindingConfiguration="MTOMOption" contract="IMath"/> </service> </services> <bindings> <wsHttpBinding> <binding name="MTOMOption" messageEncoding="Mtom"/> </wsHttpBinding> </bindings> </system.serviceModel></configuration>

Page 94: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

94 von 122School of Engineering © K. Rege, ZHAW

Endpoints

Page 95: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

95 von 122School of Engineering © K. Rege, ZHAW

Endpoint in WCF

■ Provide the necessary resources and directions, which help clients to

communicate with the various services WCF offers.

■ An endpoint completes WCF. We commonly refer the three elements (attributes)as ABC. Where

■ 01) A stands for Address

■ 02) B stands for Binding and

■ 03) C stands for Contract

ClientClient ServiceService

EndpointEndpointEndpointEndpoint

EndpointEndpoint

EndpointEndpoint

Page 96: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

96 von 122School of Engineering © K. Rege, ZHAW

ServiceService

AA

AA

ClientClient

CC

AddressWhere?

AddressWhere?

ContractWhat?

ContractWhat?

BindingHow?

BindingHow?

EndpointEndpoint

AAMessage

Address, Binding, Contract

BB AA BB

BB

BB

CC

CC

CC

Page 97: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

97 von 122School of Engineering © K. Rege, ZHAW

ServiceHostServiceHost

ClientClient ServiceService

ClientChannelClientChannel AA

AA

AAMessage

Creating Endpoints

BB

BB

BB

CC

CC

CC

Page 98: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

98 von 122School of Engineering © K. Rege, ZHAW

Hosting

Page 99: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

99 von 122School of Engineering © K. Rege, ZHAW

VS Studio Project Types

■ In VS there a Library and Application

■ Service Application: has a .svc file■ When started by default by a ASP.Net Development server is started■ You can see in the window on the right when entering the url.

■ Service Library■ thus,a WCF Service Library is e.g. self hosted.

■ hosted within another program

Page 100: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

100 von 122School of Engineering © K. Rege, ZHAW

Host Architecture

■ Every WCF service must be hosted in a Windows process called the host

process.

■ The host can be provided by■ Self Hosted: as part of the application■ IIS (http only)■ WAS the Windows Activation Service (not covered here)

Page 101: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

101 von 122School of Engineering © K. Rege, ZHAW

class HelloHost

{

static void Main(string[] args)

{

ServiceHost host = new ServiceHost(typeof(WCFServiceLibrary1.service1));

host.Open();

// Wait until done accepting connections

Console.ReadLine();

host.Close();

}

}

class HelloHost

{

static void Main(string[] args)

{

ServiceHost host = new ServiceHost(typeof(WCFServiceLibrary1.service1));

host.Open();

// Wait until done accepting connections

Console.ReadLine();

host.Close();

}

}

■ The developer is responsible for providing and managing the life cycle of the host process.

■ Self-hosting is used to■ cross a process (or machine) boundary■ using the service in-proc (in the same process as the client)

Self Hosting

Page 102: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

102 von 122School of Engineering © K. Rege, ZHAW

<?xml version="1.0" encoding="utf-8" ?>

<configuration>

<system.serviceModel> <services>

<service name="WCFServiceLibrary1.HelloService"

behaviorConfiguration="MyServiceTypeBehaviors">

<endpoint contract="WCFServiceLibrary1.IService1" binding="basicHttpBinding"/>

<baseAddress>

<add baseAddress = "http://localhost:8082/*" />

</baseAddress>

</service>

</services>

<behaviors>

<serviceBehaviors>

<behavior name="MyServiceTypeBehaviors" >

<serviceMetadata httpGetEnabled="true" />

</behavior>

</serviceBehaviors>

</behaviors>

</system.serviceModel>

</configuration>

<?xml version="1.0" encoding="utf-8" ?>

<configuration>

<system.serviceModel> <services>

<service name="WCFServiceLibrary1.HelloService"

behaviorConfiguration="MyServiceTypeBehaviors">

<endpoint contract="WCFServiceLibrary1.IService1" binding="basicHttpBinding"/>

<baseAddress>

<add baseAddress = "http://localhost:8082/*" />

</baseAddress>

</service>

</services>

<behaviors>

<serviceBehaviors>

<behavior name="MyServiceTypeBehaviors" >

<serviceMetadata httpGetEnabled="true" />

</behavior>

</serviceBehaviors>

</behaviors>

</system.serviceModel>

</configuration>

<app>.config

For a process that hosts a Service a configuration file has to be provided

Service Configuration

to allow for "?wsdl"

Page 103: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

103 von 122School of Engineering © K. Rege, ZHAW

IIS Hosting

<%@ ServiceHost Language="C#" Service="HelloService"CodeBehind = "HelloService.cs" %>

<%@ ServiceHost Language="C#" Service="HelloService"CodeBehind = "HelloService.cs" %>

HelloService.svc

<?xml version="1.0" encoding="utf-8" ?><configuration> <system.serviceModel> <services> <service name="WCFServiceLibrary1.HelloService"

behaviorConfiguration="MyServiceTypeBehaviors"> <endpoint contract="WCFServiceLibrary1.IService1"

binding="basicHttpBinding"/> </service> </services> <behaviors> <serviceBehaviors> <behavior name="MyServiceTypeBehaviors" > <serviceMetadata httpGetEnabled="true" /> </behavior> </serviceBehaviors> </behaviors>

</system.serviceModel></configuration>

<?xml version="1.0" encoding="utf-8" ?><configuration> <system.serviceModel> <services> <service name="WCFServiceLibrary1.HelloService"

behaviorConfiguration="MyServiceTypeBehaviors"> <endpoint contract="WCFServiceLibrary1.IService1"

binding="basicHttpBinding"/> </service> </services> <behaviors> <serviceBehaviors> <behavior name="MyServiceTypeBehaviors" > <serviceMetadata httpGetEnabled="true" /> </behavior> </serviceBehaviors> </behaviors>

</system.serviceModel></configuration>

web.config located in \App_Code

No BaseAddress

Page 104: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

104 von 122School of Engineering © K. Rege, ZHAW

Clients

Page 105: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

105 von 122School of Engineering © K. Rege, ZHAW

Client Implementation via VS generated Proxy

■ Service Description is accessible

■ Visual Studio■ Add Service Reference

http://localhost:8082/HelloService

Page 106: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

106 von 122School of Engineering © K. Rege, ZHAW

■ Command Line

SvcUtil http://localhost/HelloService/HelloService.svc /out:Proxy.cs

■ Channel generated via Factory

class Client { static void Main() { IHello proxy = new ChannelFactory<IHello>("HelloEndpoint").

CreateChannel(); string r = proxy.Hello("Christian"); Console.WriteLine(r); }}

class Client { static void Main() { IHello proxy = new ChannelFactory<IHello>("HelloEndpoint").

CreateChannel(); string r = proxy.Hello("Christian"); Console.WriteLine(r); }}

<system.serviceModel> <client> <endpoint name="HelloEndpoint" address="http://localhost/HelloService" binding="basicHttpBinding" contract="IHello" /> </client></system.serviceModel>

<system.serviceModel> <client> <endpoint name="HelloEndpoint" address="http://localhost/HelloService" binding="basicHttpBinding" contract="IHello" /> </client></system.serviceModel>

app.config

defines wherethe Service islocated

Client Implementation via CLI

Page 107: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

107 von 122School of Engineering © K. Rege, ZHAW

Summary

Page 108: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

108 von 122School of Engineering © K. Rege, ZHAW

Features Summary - WCF

AddressAddress BindingBinding BehaviorBehaviorContractContractHTTPTransport

TCPTransport

NamedPipeTransport

MSMQTransport

CustomTransport

WS-SecurityProtocol

WS-RMProtocol

WS-Coord

Protocol

DuplexChannel

CustomProtocol

http://...http://...

net.tcp://...net.tcp://...

net.pipe://...net.pipe://...

net.msmq://...net.msmq://...

xxx://...xxx://...

ThrottlingBehavior

MetadataBehavior

ErrorBehavior

CustomBehavior

InstancingBehavior

ConcurrencyBehavior

TransactionBehavior

SecurityBehavior

Request/Response

One-WayOne-Way

Duplex

net.p2p://...net.p2p://...

PeerTransport

Externally visible,per-endpoint

Opaque, per-service,endpoint, or operation

Page 109: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

109 von 122School of Engineering © K. Rege, ZHAW

Questions ?

I like WCF buthate meteorites

Page 110: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

110 von 122School of Engineering © K. Rege, ZHAW

AppendixSecurity

Page 111: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

111 von 122School of Engineering © K. Rege, ZHAW

Security in WCF

■ The Security of WCF offers two things■ Secure transmission of messages between entities■ Access Control - Restrict access to resources from entities

■ Entity■ Person, business, application

■ Resource■ Files, server, operation

Page 112: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

112 von 122School of Engineering © K. Rege, ZHAW

Message Security

■ Confidential

■ Integrity

■ Authentication

■ Authorization

■ prob. Logging/Auditing

Page 113: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

113 von 122School of Engineering © K. Rege, ZHAW

Testimonials of Credentials

■ Evidence■ Information about an entity■ Used to control access to resources

■ Statements■ Certified statements by ratings of a trusted instance

■ Proof of Possession■ How an entity proves its statements

Page 114: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

114 von 122School of Engineering © K. Rege, ZHAW

The Safety Model in WCF

■ Based on Evidence and Statements■ Can offer desired safety requirements

■ As Safe as the basic setting■ Except for interoperability

■ Consistent between settings (bindings)

■ Consistent between ratings

Page 115: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

115 von 122School of Engineering © K. Rege, ZHAW

Transport Level Security

■ The security requirements are offered on the transport layer

■ Advantages■ Good performance■ Common implementation■ Small changes

■ Drawbacks■ Limited Scope i.e. application■ No end-to-end Security

Page 116: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

116 von 122School of Engineering © K. Rege, ZHAW

Transport Level Security

■ Transport Level Security can be enabled by configuration

<endpoint address="https://localhost/calculator" binding="basicHttpBinding" bindingConfiguration="SSLBinding" contract="ICalculator" />

<basicHttpBinding> <binding name="SSLBinding"> <security mode="Transport"> <transport clientCredentialType="None"/> </security> </binding></basicHttpBinding>

Page 117: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

117 von 122School of Engineering © K. Rege, ZHAW

Message Level Security

■ Security is provided on the message level

■ Advantages■ Wider scope

■ Expandable■ end-to-end Security

■ Drawbacks■ Standards and usage are extremely complex■ Some impact on performance

Page 118: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

118 von 122School of Engineering © K. Rege, ZHAW

Message Level Security

■ Message Level Security can be enabled by configuration

<endpoint address="http://localhost/calculator" binding="wsHttpBinding" bindingConfiguration="WSBinding" contract="ICalculator" />

<wsHttpBinding> <binding name="WSBinding"> <security mode="Message"> <message clientCredentialType="Windows"/> </security> </binding></wsHttpBinding>

Page 119: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

119 von 122School of Engineering © K. Rege, ZHAW

Mixed Mode

■ Compromise between security at the transport and message level

■ Transport The level offers privacy and confidentiality■ Benefits for performance

■ The message level handles credentials■ Rich set of possible "evidences", expandable

Page 120: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

120 von 122School of Engineering © K. Rege, ZHAW

"Mixed Mode"

■ Set by Configuration

<endpoint address="https://localhost/calculator" binding="wsHttpBinding" bindingConfiguration="MixedBinding" contract="ICalculator" />

<wsHttpBinding> <binding name="MixedBinding"> <security mode=" TransportWithMessageCredential"> <message clientCredentialType="Windows"/> </security> </binding></wsHttpBinding>

Page 121: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

121 von 122School of Engineering © K. Rege, ZHAW

Username/Password as Credentials

■ Can be set by the application/ client - code

Console.WriteLine(" Enter username[domain\\user]:");string username = Console.ReadLine();Console.WriteLine(" Enter password:");string password = Console.ReadLine();

CalculatorProxy wsProxy = new CalculatorProxy();wsProxy.ChannelFactory.Credentials. UserName.UserName = username;wsProxy.ChannelFactory.Credentials. UserName.Password = password;

Page 122: Windows Communication Foundationradar.zhaw.ch/~rege/dnet_fs20/dnet2_5.pdf · INNOVATION 2.0 Windows Communication Foundation Enterprise Applications WCF Goals and Reasoning Why it

122 von 122School of Engineering © K. Rege, ZHAW

"PrincipalPermission"

■ Built in Windows User Credentials may be applied

[PrincipalPermission(SecurityAction.Demand, Role="Builtin\\Administrators")]public double Mul(int a, int b){ return a * b;}

<behaviors> <behavior name="BuiltinSecurity"> <serviceAuthorization principalPermissionMode="UseWindowsGroups"/> </behavior></behaviors>


Recommended