Christian Weyer Level 200 thinktecture [email protected] Session Code: INT302 and Christian Weyer Support & consulting for Windows and .NET software developers and architects (we are based.

Download Report

Transcript Christian Weyer Level 200 thinktecture [email protected] Session Code: INT302 and Christian Weyer Support & consulting for Windows and .NET software developers and architects (we are based.

Christian Weyer
Level 200
thinktecture
[email protected]
Session Code: INT302
and Christian Weyer
Support & consulting for Windows and .NET software
developers and architects (we are based in Germany)
Developer coaching and mentoring
Architecture consulting and prototyping
Architecture and code reviews
Application optimization, troubleshooting, debugging
Focus on distributed applications, service orientation,
workflows, cloud computing, interoperability, security,
end-to-end solutions
Windows Server, WCF, WF, MSMQ, .NET Services, Windows Azure
http://www.thinktecture.com
[email protected]
Agenda
Config & Hosting
Discovery
Routing
REST
This & that
Not in Scope: Workflow Services
3
Theme: "Help! WCF4 to the rescue…!?"
4 major topics
What is not so good in WCF 3.x?
What could WCF4 do better?
Show it to me!
"My service config files look more
complicated than my service code!"
Source: http://www.flickr.com/photos/liboni/2061335442
WCF4
Simplified
Configuration
New Feature #1:
Config & Hosting
No need for <service> tag to configure a
service
Configuration of default bindings and behaviors
Re-usable system-provided endpoint
configurations, aka standard endpoints
Support for .svc-less activation
7
Config & Hosting: Default Endpoints
Simplified configuration for default scenarios
ServiceHost serviceHost = new
ServiceHost(typeof(HelloService),
new Uri("http://localhost:7777/Services/Hello"),
new Uri("net.tcp://localhost:7778/Services/Hello"));
serviceHost.Open();
Console.WriteLine("WCF Service is running.");
Console.WriteLine("Press <ENTER> to terminate service.");
Console.ReadLine();
serviceHost.Close();
…
<configuration>
</configuration>
8
Config & Hosting: Default Endpoints
Default endpoint behavior only kicks in when service
has not been configured with any endpoints
Call host.AddDefaultEndpoints() to add set of
default endpoints
9
Config & Hosting: Default Bindings
Define standard settings for default bindings
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding maxReceivedMessageSize="9999999">
<readerQuotas maxArrayLength="9999999"/>
</binding>
</basicHttpBinding>
</bindings>
No name attribute
</system.serviceModel>
10
Config & Hosting: Default Behaviors
Define standard settings for behaviors
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
No name attribute
</system.serviceModel>
11
Config & Hosting: Protocol Mappings
Can redefine default protocol mappings for
bindings for global use
Pre-configured default bindings
<protocolMapping>
<add scheme="http" binding="basicHttpBinding"/>
<add scheme="net.tcp" binding="netTcpBinding"/>
<add scheme="net.pipe" binding="netNamedPipeBinding"/>
<add scheme="net.msmq" binding="netMsmqBinding"/>
</protocolMapping>
12
Config & Hosting: Protocol Mappings
Add or replace your own protocol mapping
configuration
<protocolMapping>
<clear scheme="http" />
<add scheme="http" binding="customBinding"
bindingConfiguration="binaryHttp" />
</protocolMapping>
<bindings>
<customBinding>
<binding name="binaryHttp">
<binaryMessageEncoding/>
<httpTransport/>
</binding>
</customBinding>
</bindings>
13
Config & Hosting: Standard Endpoints
Reusable pre-configured system endpoints
endpoints in WCF have many moving parts
(address, binding, contract, behaviors)
in some cases some of these parts are constrained
most common with infrastructure or system endpoints
where the contract is fixed and provided externally to the
service
Specify a standard endpoint by using kind attribute
<system.serviceModel>
<services>
<service name="HelloService">
<endpoint kind="udpDiscoveryEndpoint" />
</service>
</services>
…
</system.serviceModel>
14
.svc-less Activation
No longer need to have a physical .svc file for each
service
specify activation path in web.config
<system.serviceModel>
<serviceHostingEnvironment>
<serviceActivations>
<add relativeAddress="/Hello.svc"
service="HelloService"/>
</serviceActivations>
</serviceHostingEnvironment>
<services>
<service name="HelloService">
<endpoint binding="webHttpBinding"
contract="IHelloService" />
</service>
</services>
[...]
15
"I need to provide one single endpoint
to my clients, but support multiple
services (in multiple versions)!"
Source: http://ciscorouting.com/routing_engine.jpg
WCF4
Routing
Service
New Feature #2:
Routing
Intermediate Routing Pattern is a well understood
pattern in enterprise architecture
just one service entry point with a universal contract
route incoming messages to the appropriate
business services
use it to determine path of a message within a system
there can be a cascade of routers each responsible for different
aspects of routing messages
WCF 4 now provides a
SOAP-based RoutingService
routes, tables, and filters
configurable
18
Routing: Sample Architecture
Binding/
protocol Y
Consumer
Binding/
protocol X
Router
Service
Tables
Service B
Filters
config
19
Service A
Binding/
protocol Z
Service C
Routing
Host RoutingService in any WCF host
Use routing tables and filters to configure routing
rules
<client>
<endpoint name="HelloService"
address="http://..."
binding="basicHttpBinding" contract="*" />
</client>
<routing>
<filters>
<filter name="MatchAllFilter" filterType="MatchAll" />
</filters>
<filterTables>
<filterTable name="mainRoutingTable">
<add filterName="MatchAllFilter"
endpointName="HelloService" />
</filterTable>
</routingTables>
</routing>
20
"ABC?
My client applications should just know
about the contract, nothing more!"
Source: http://www.flickr.com/photos/97705796@N00/3577907718
WCF4
Discovery
New Feature #3 :
Discovery
WS-Discovery as standard discovery mechanism
e.g. printer can use WS-Discovery to announce presence on
a network
can be discovered by different applications that require
printing documents
Windows Vista's (and up) contact location feature
WCF services can be made discoverable
on a local subnet ad-hoc (using WS-Discovery over UDP)
on larger managed networks (using WS-Discovery proxy)
WCF clients can discover services on a local subnet or a
larger managed networks
23
Discovery: Ad-Hoc
Service config:
<system.serviceModel>
<services>
<service name="HelloService"
behaviorConfiguration="serviceBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:7777/Services/Hello"/>
</baseAddresses>
</host>
<endpoint binding="basicHttpBinding"
contract="IHelloService" />
<endpoint name="udpDiscovery" kind="udpDiscoveryEndpoint"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="serviceBehavior">
<serviceDiscovery />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
24
Discovery: Ad-Hoc
Client code:
DiscoveryClient discoveryClient = new
DiscoveryClient("udpDiscoveryEndpoint");
FindCriteria findCriteria = new FindCriteria(typeof(IHelloService));
FindResponse findResponse = discoveryClient.Find(findCriteria);
if (findResponse.Endpoints.Count > 0)
{
EndpointAddress address = findResponse.Endpoints[0].Address;
ChannelFactory<IHelloServiceChannel> factory =
new ChannelFactory<IHelloServiceChannel>(
new BasicHttpBinding(), address);
IHelloServiceChannel client = new factory.CreateChannel();
client.SayIt("Hello from WCF4!");
}
25
client.Close();
factory.Close();
Discovery: Probes & Announcements
Discovery
Client
Discovery
Client
Probe
Announcements
(Hello / Goodbye)
Service A
26
Service B
Service A
Service B
Discovery: Announcements
Service config:
<behaviors>
<serviceBehaviors>
<behavior name="serviceBehavior">
<serviceDiscovery>
<announcementEndpoints>
<endpoint name="udpAnnouncement"
kind="udpAnnouncementEndpoint"/>
</announcementEndpoints>
</serviceDiscovery>
</behavior>
</serviceBehaviors>
</behaviors>
Use AnnouncementService API on consuming
side to subscribe to events
Can use this approach to build service-oriented peer
solutions
27
"Give me a little bit more REST-fulness in
WCF!"
Source: http://www.annisonne.de/resources/bild18.jpg
WCF4
REST Support
New Feature #4:
Enhanced REST Support
Caching support in IIS/WAS
ASP.NET Routing integration
Dynamic content types
"
Helper methods for creating content
Improved exception support
JSONP support for AJAX Services
Automatically generated help page
30
Dynamic Content
Dynamic content types are now supported
based on Content-Type and Accepts headers
WCF can automatically create response format
Developer can decide to opt-in manually
Helper methods for creating
content
"
Available through WebOperationContext
public
public
public
public
public
public
31
Message
Message
Message
Message
Message
Message
CreateAtom10Response(...);
CreateJsonResponse<T>(...);
CreateStreamResponse(...);
CreateTextResponse(...);
CreateXmlResponse(...);
CreateXmlResponse<T>(...);
JSONP for AJAX-enabled Services
JSON with Padding
convention used to invoke cross-domain scripts by
generating script tags in the current document
result is returned in a specified callback function
<script src="http://..."> can evaluate scripts from any
domain
script retrieved by those tags is evaluated within a scope in
which other functions may already be defined
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<standardEndpoints>
<webScriptEndpoint>
<standardEndpoint crossDomainScriptAccessEnabled="true"/>
</webScriptEndpoint>
</standardEndpoints>
</system.serviceModel>
32
Small, but good things
Source: http://www.flickr.com/photos/25750231@N07/2943443607
WCF4
Miscellaneous
New Feature #X:
This & that: Throttles
Controlling resource usage on the service side through
throttling
.NET 3.5 SP1 (different settings before)
MaxConcurrentSessions: default is 10
MaxConcurrentCalls: default is 16
MaxConcurrentInstances: default is 26
.NET 4.0
MaxConcurrentSessions: default is 100 * processor
count
MaxConcurrentCalls: default is 16 * processor count
MaxConcurrentInstances: default is
MaxConcurrentSessions + MaxConcurrentCalls
35
This & that: Even More
Non-destructive queue receive
adds "peek / lock“ mechanism to WCF MSMQ channel
ETW tracing integration
Metadata
new behavior allowing to modify returned metadata XML to
fix-up URLs based on incoming request's host header/port
WS-I Basic Profile 1.2
supports WS-Addressing and MTOM
Compression
support for automatic response decompression over HTTP
(e.g. with IIS)
DataContractSerializer enhancements
Numerous fixes
36
Resources
Christian Weyer‘s blog posts for WCF 4.0 Beta 1
Simplified configuration – or: “Look ma: my config
shrinks!”
http://blogs.thinktecture.com/cweyer/archive/2009/05/0
7/415326.aspx
.svc-less Activation – or: “Look ma: my [REST] URLs
look good!”
http://blogs.thinktecture.com/cweyer/archive/2009/05/0
8/415327.aspx
Dynamic service and endpoint discovery – or: “Look
ma: I just need the contract to talk to my service!”
http://blogs.thinktecture.com/cweyer/archive/2009/05/0
8/415329.aspx
37
Resources
Standard endpoints – or: “Look ma: streamlined
infrastructure and system endpoints!”
http://blogs.thinktecture.com/cweyer/archive/2009/05/08/415330.
aspx
Discovery announcements – or: “Look ma: I can see when
my service goes online or offline!”
http://blogs.thinktecture.com/cweyer/archive/2009/05/08/415332.
aspx
Routing Service – or: “Look ma: Just one service to talk to!”
http://blogs.thinktecture.com/cweyer/archive/2009/05/08/415335.
aspx
Protocol bridging & fault tolerance with the Routing Service
– or: “Look ma: Really just one service to talk to!”
http://blogs.thinktecture.com/cweyer/archive/2009/05/08/415341.
aspx
38
Resources
Email Christian Weyer
[email protected]
Weblog Christian Weyer
http://blogs.thinktecture.com/cweyer
thinktecture
http://www.thinktecture.com
39
Summary
WCF is still… WCF!
ABC is still there 
No big changes, but further investment into the
foundation
smaller steps than compared to other areas in .NET
Framework, e.g. WF4
Discovery can be interesting especially for enterprise
scenarios
Routing often needed in more complex architectures
A bit more REST-fulness
40
© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.
The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should
not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS,
IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.