在好例子网,分享、交流、成长!
您当前所在位置:首页C# 开发实例C#网络编程 → WCF-Essential Windows Communication Foundation for .NET Framework 3.5.(2008)

WCF-Essential Windows Communication Foundation for .NET Framework 3.5.(2008)

C#网络编程

下载此实例

实例介绍

【实例简介】WCF-Essential Windows Communication Foundation for .NET Framework 3.5.(2008)

【实例截图】

【核心代码】

Contents
Foreword xxv
Preface xxvii
Acknowledgments xxxiii
1 Basics 1
Why WCF Matters 1
Introduction 3
Implementing a WCF Service 6
Just the ABCs 7
Writing a WCF Service Entirely in Code 7
Writing a Service with Code and Configuration Files 10
More on Configuration Files 12
More on Service Hosting 13
Exposing the Metadata Exchange (MEX) Endpoint 14
Implementing a Client for a WCF Service 18
Writing a WCF Client Entirely in Code 18
Writing a Client with Code and Configuration 19
Hosting a Service in IIS 23
Discussion 23
Hosting a Service in IIS in Three Steps 24
Implementing a WCF Client for an ASMX Service 27
Tools Support 27
Generating Client Proxy Class and Configuration Files 28
ix
2 Contracts 33
Service Contracts 37
Synchronous Request-Response Operations 38
Asynchronous Request-Response Operations 41
One-Way Operations 44
Duplex Operations 46
Multiple Contracts and Endpoints in a Service 54
Names of Operations, Types, Actions, and Namespaces in WSDL 57
Data Contracts 60
Defining XML Schema for a .NET Class 62
Defining Class Hierarchies 65
Exposing Additional Types in WSDL with KnownTypes 67
Versioning Data Contracts 72
Data Contract Equivalence 75
Working with Collections 76
Message Contracts 78
Typed Messages 79
Untyped Messages 82
Using SOAP Headers with Untyped Messages 85
3 Channels 91
Channel Shapes 94
One-Way Communication Pattern 94
Duplex Communication 95
Request-Reply Communication 97
Shape Changing 98
Operation Contract and Channel Shapes 99
Channel Listeners 101
Channel Factories 102
ChannelFactory<> 104
ICommunicationObject 105
4 Bindings 111
Choosing an Appropriate Binding 116
Sample Application 119
Contents x
Cross-Machine Communication Between .NET Applications 123
netTcpBinding 123
Local Machine Communication Between .NET Applications 127
netNamedPipeBinding 128
Communication Using Basic Web Services 131
basicHttpBinding 132
Communication Using Advanced Web Services 135
wsHttpBinding 137
ws2007HttpBinding 140
wsDualHttpBinding 143
Comparing Binding Performance and Scalability 152
Communication Using Queued Services 154
netMsmqBinding 155
msmqIntegrationBinding 165
Creating a Custom Binding 168
User-Defined Bindings 171
Binding Elements 171
Transports 172
Encoders 173
Security 174
Transport Upgrades/Helpers 175
Shape Change 176
Other Protocols 177
Exposing a Service Contract over Multiple Bindings 177
5 Behaviors 181
Concurrency and Instancing (Service Behavior) 184
Default Concurrency and Instancing with Sessionless Binding 187
Multithreading a Single Instance 189
Implementing a Singleton 190
Session-Level Instances 193
Controlling the Number of Concurrent Instances 195
Controlling the Number of Concurrent Calls 199
Controlling the Number of Concurrent Sessions 201
Exporting and Publishing Metadata (Service Behavior) 204
Contents xi
Implementing Transactions (Operation Behavior) 207
Transactional Operations Within a Service 208
Flowing Transactions Across Operations 215
Choosing a Transaction Protocol—OleTx or WS-AT 221
Transaction Service Behaviors 223
Implementing Custom Behaviors 224
Implementing a Message Inspector for Service Endpoint Behavior 227
Exposing a Parameter Inspector for Service Operation Behavior
as an Attribute 230
Exposing a Service Behavior Through Configuration 233
Security Behaviors 237
6 Serialization and Encoding 241
Serialization Versus Encoding 241
Comparing WCF Serialization Options 243
DataContractSerializer 243
NetDataContractSerializer 247
XmlSerializer 249
DataContractJsonSerializer 252
Choosing a Serializer 254
Preserving References and Cyclical References 254
Sharing Type with the NetDataContractSerializer 260
Roundtrip Serialization Using IExtensibleDataObject 264
Serializing Types Using Surrogates 270
Streaming Large Data 276
Using the XmlSerializer for Custom Serialization 277
Custom XmlSerialization Using Attributes 278
Custom XmlSerialization Using IXmlSerializable 279
Choosing an Encoder 281
Text Versus Binary Encoding 282
Sending Binary Data Using MTOM Encoding 283
Getting to Know the WebMessageEncoder 284
7 Hosting 287
Hosting a Service in Windows Process Activation Services 288
Hosting a Service in IIS 7 292
Contents xii
Enabling ASMX Features in an IIS-Hosted Service 294
Self-Hosting 301
Self-Hosting in a Managed Windows Service 302
Hosting Multiple Services in One Process 305
Defining Service and Endpoint Addresses 308
8 Security 315
WCF Security Concepts 316
Authentication 316
Authorization 316
Confidentiality 317
Integrity 317
Transport and Message Security 317
Certificate-Based Encryption 319
Concepts 319
Setup 320
Transport-Level Security 322
Encryption Using SSL 323
Client Authentication 327
Service Identity 332
Message-Level Security 334
Authenticating with wsHttpBinding 335
Securing Services with Windows Integrated Security 340
Section Examples Introduction 341
Authenticating Users with Windows Credentials 343
Authorizing Users with Windows Credentials 346
Authorization Using AzMan 348
Impersonating Users 353
Securing Services over the Internet 358
ASP.NET Integration 360
Authentication Using Membership Providers 361
Role-Based Authorization Using Role Providers 364
Using Forms Authentication 366
Logging and Auditing 371
Contents xiii
9 Diagnostics 375
Sample WCF Application 376
Tracing 376
End-to-End Tracing 377
Activities and Correlation 378
Enabling Tracing 379
Verbosity Recommendations 381
Message Logging 381
Enabling Message Logging 381
Additional Configuration Options 383
Shared Listeners 384
Message Filters 384
Trace Source Auto Flushing 385
Performance Counters 386
Windows Management Instrumentation (WMI) 387
Using the Service Configuration Editor 387
Tracing Options 389
Logging Options 389
Configuring Sources 390
Configuring Listeners 391
Service Trace Viewer 393
Activity View 393
Project View 395
Message View 395
Graph View 395
Analyzing Logs from Multiple Sources 397
Filtering Results 400
10 Exception Handling 403
Introduction to WCF Exception Handling 404
WCF Exception Communication via SOAP 404
Unhandled Exception Example 405
Detecting and Recovering a Faulted Channel 408
Communicating Exception Details 409
Managing Service Exceptions with FaultException 411
Using FaultCode and FaultReason to Extend FaultException 412
Contents xiv
Limitations of Basic FaultExceptions 414
Creating and Consuming Strongly Typed Faults 415
Declaring Fault Definitions with FaultContract 415
Defining a FaultContract 417
Throwing a FaultException<> with a Defined FaultContract 418
Fault Contract Strategies 419
Implementing Client Fault Handlers 419
Error-Handling Application Block 420
Exception Shielding 421
11 Workflow Services 423
Integration Points 424
Calling a WCF Service from WF 426
Using a Send Activity 427
Writing a Custom Activity 430
Exposing a Service from WF 433
Define the Interface 434
Receive Activity 435
Configuration in app.config 439
Hosting a Service-Enabled Workflow 441
Self-Hosting a Service-Enabled Workflow 442
Hosting a Service-Enabled Workflow in IIS 443
Correlation and Durable Services 444
Long-Running Workflow 445
Handling the Context 450
Persisting Workflow State on the Server 452
Controlling Access to Service-Enabled Workflows 454
Declarative Access Control 455
Programmatic Access Control 455
12 Peer Networking 459
Approaches to Building Distributed Applications 459
Client/Server Applications 460
N-Tier Applications 460
Peer-to-Peer Applications 461
Comparison of Distributed Approaches 462
Contents xv
Peer-to-Peer Applications 462
Mesh Networks 462
Resolving Peer Meshes 464
Message Flooding Versus Directional Messaging 464
Creating Peer-to-Peer Applications 465
netPeerTcpBinding 465
Resolving Peers Using PNRP 468
PNRP Bootstrap Process 469
Windows Internet Computer Names 469
PnrpPeerResolver 470
Mesh Authentication 471
Registering Names Using PNRP 471
System.Net.Peer 472
Implementing a Custom Peer Resolver 474
Limiting the Number of Hops for a Message 478
Collaboration Using Windows Vista 480
People Near Me 481
Windows Contacts 482
Invitations 483
System.Net.PeerToPeer.Collaboration 485
Directional Messaging Using Custom Binding 492
13 Programmable Web 503
All About the URI 504
The Ubiquitous GET 506
Format Matters 507
Web Programming with WCF 507
URI and UriTemplates 508
Building URIs 509
Parsing URIs 510
Creating Operations for the Web 511
Hosting Using WebHttpBinding 512
Using WebGet and WebInvoke 514
WebGet 514
WebInvoke 514
Contents xvi
Programming the Web with AJAX and JSON 516
ASP.NET AJAX Integration 516
Using the WebOperationContext 523
Hosting for the Web 530
WebScriptServiceHost 530
WebScriptServiceHostFactory 530
Content Syndication with RSS and ATOM 531
Appendix Advanced Topics 537
Publishing Metadata Endpoints 537
mexHttpBinding 538
mexNamedPipeBinding 538
mexTcpBinding 538
mexHttpsBinding 539
Creating Clients from Metadata 539
Creating Silverlight Clients from Metadata 541
Sharing Ports Between Services 542
Configuring Service Quota Settings 543
Configuring HTTP Connections 545
Recycling Idle Connections 546
Adjusting Connection Lifetime 546
Disabling HTTP Keep-Alives 547
Increasing Number of Connections 549
Configuring TCP Connections 549
Recycling Idle Connections 549
Adjusting Connection Lifetime 550
Increasing Number of Connections 550
Using LINQ with WCF 550
Exposing LINQ-to-SQL Entities 550
Index 553
Contents xvii
This page intentionally left blank
Figures
Figure 1.1: Communication between client and service 4
Figure 1.2: Communication between client and service endpoints 5
Figure 1.3: Hosting a service 6
Figure 1.4: Obtaining metadata through MEX endpoint 15
Figure 1.5: Visual Studio generating client proxy class and configuration file 21
Figure 2.1: High-level translation of code artifacts to WSDL 37
Figure 2.2: High-level translation of code syntax to WSDL 38
Figure 2.3: Synchronous request-response communication 38
Figure 2.4: Specifying asynchronous methods in Add Service Reference 42
Figure 2.5: Asynchronous request-response communication 43
Figure 2.6: Duplex communication 47
Figure 2.7: High-level translation of code artifacts to XSD 61
Figure 2.8: High-level translation of code syntax to XSD 62
Figure 2.9: Specifying message contracts in Add Service Reference 80
Figure 3.1: Channel stack 93
Figure 3.2: One-way communication 95
Figure 3.3: Duplex communication 96
Figure 3.4: Request-reply communication 97
Figure 3.5: ICommunicationObject state diagram 107
xix
Figure 4.1: Binding Explorer 115
Figure 4.2: Selecting a binding 118
Figure 4.3: Average response time 153
Figure 4.4: Operations per second 153
Figure 4.5: Cost per operation 154
Figure 5.1: Behavior elements 183
Figure 5.2: Output from default InstanceContextMode and ConcurrencyMode with
sessionless binding 189
Figure 5.3: Output from InstanceContextMode.Single and ConcurrencyMode.
Multiple 191
Figure 5.4: Output from singleton: InstanceContextMode.Single and
ConcurrencyMode.Single 192
Figure 5.5: Output from session-aware service 196
Figure 5.6: Output controlling the number of concurrent instances 199
Figure 5.7: Output controlling the number of concurrent calls 202
Figure 5.8: Output controlling the number of concurrent sessions 204
Figure 5.9: ACID transaction within an operation 209
Figure 5.10: Output from transactional service showing local and distributed
transaction IDs 214
Figure 5.11: Output from optimized transactional service 215
Figure 5.12: Transaction that spans service boundaries 216
Figure 5.13: Output from two transactional services coordinated in a single
transaction 221
Figure 5.14: Interfaces for building custom behaviors on the client 225
Figure 5.15: Interfaces for building custom behaviors on the server 225
Figure 6.1: XML Information Set 242
Figure 6.2: XSD types 244
Figure 7.1: WAS architecture 289
Figure 7.2: Enabling Windows Process Activation Services 290
Figure 7.3: Enabling WCF non-HTTP activation 290
Figure 7.4: IIS implemented on WAS 293
Figure 7.5: Service control manager 305
Figure 7.6: Viewing address and binding from a running service 311
Figures xx
Figure 8.1: Configuring IIS 7 for SSL 324
Figure 8.2: Services over corporate LAN with Windows application 341
Figure 8.3: Configuring an XML Authorization store 349
Figure 8.4: Creating a role definition with Authorization Manager 350
Figure 8.5: Authorization Manager showing example configuration 351
Figure 8.6: Services over Internet with Windows application 359
Figure 8.7: Sample Internet application 359
Figure 8.8: Services over Internet with Web application 367
Figure 9.1: Tracing and MessageLogging enabled 388
Figure 9.2: Advanced Message Logging settings 389
Figure 9.3: Message Logging XPath Filter 390
Figure 9.4: Trace Source settings 391
Figure 9.5: Listener settings 392
Figure 9.6: Detailed listener configuration 392
Figure 9.7: Service Trace Viewer with client trace and message logs 394
Figure 9.8: Service Trace Viewer Message view 396
Figure 9.9: Service Trace Viewer Graph view 396
Figure 9.10: Service Trace Viewer with service and client logs loaded 398
Figure 9.11: Service Trace Viewer graph of activity transfer 399
Figure 9.12: Service Trace Viewer with expanded subtract call activity 400
Figure 9.13: Creating a custom filter in the Service Trace Viewer 401
Figure 10.1: FaultException returned by calling service with zero denominator 407
Figure 10.2: CommunicationObjectFaultedException for faulted channel 407
Figure 10.3: Exception detail included with ServiceDebugBehavior 410
Figure 11.1: WF behaviors 426
Figure 11.2: Adding a Send activity to a workflow design surface 428
Figure 11.3: Proxy type was imported so an operation can be chosen 429
Figure 11.4: Binding WF variable to service operation parameters 430
Figure 11.5: Using a custom activity in a workflow 433
Figure 11.6: Adding a Receive activity to the workflow design surface 436
Figure 11.7: Entering or importing an interface for a Receive activity 437
Figure 11.8: Binding operation contract parameters to workflow variables 438
Figures xxi
Figure 11.9: Workflow exposing one Receive activity 439
Figure 11.10: Composite Receive activity in a long-running workflow 446
Figure 11.11: Completing a long-running workflow 448
Figure 11.12: One client maintaining context with multiple calls to a
workflow instance 451
Figure 11.13: Multiple clients maintaining context with multiple calls to a
workflow instance 452
Figure 11.14: Declarative authorization within a Receive activity 456
Figure 12.1: Client/server model 460
Figure 12.2: Three-tier model 461
Figure 12.3: Peer model with three nodes 461
Figure 12.4: Fully connected mesh 463
Figure 12.5: Partially connected mesh 464
Figure 12.6: Windows Internet Computer Name (WICN) 470
Figure 12.7: Number of hops across connected nodes 479
Figure 12.8: People Near Me Control Panel 481
Figure 12.9: Allow invitations 482
Figure 12.10: Windows Contacts 482
Figure 12.11: Windows Contact Properties 483
Figure 12.12: Windows Meeting Space invitation 484
Figure 12.13: Windows Meeting Space invitation details 484
Figure 12.14: Peer Chat sample application 485
Figure 12.15: Enabling Teredo using NetSh 500
Figure 13.1: Response in browser using WebHttpBinding binding 514
Figure 13.2: XBOX 360 Game Review AJAX-enabled application 517
Figure 13.3: Wallpaper Web application 524
Figure A.1: Starting Net.Tcp Port Sharing Service from command line 543
Figure A.2: IIS 7.0 settings for HTTP Keep-Alives 548
Figure A.3: LINQ-to-SQL Object Relational Designer 551
Figures xxii
Tables
Table 1.1: Options for Generating Proxy Class and Configuration File 28
Table 2.1: WSDL Elements 35
Table 2.2: Paired One-Way Versus Duplex Contracts for Bidirectional
Communication 48
Table 2.3: WCF Attributes That Override Default WSDL Names 58
Table 3.1: Channel Shapes Based on OperationContract Attributes 100
Table 4.1: WCF Communication Bindings in .NET Framework 3.5 112
Table 4.2: Supported Features of Each Binding 117
Table 4.3: netTcpBinding Binding Properties 124
Table 4.4: netNamedPipeBinding Binding Properties 129
Table 4.5: basicHttpBinding Binding Properties 133
Table 4.6: WS-* Specifications Supported by the wsHttpBinding Binding 136
Table 4.7: wsHttpBinding Binding Properties 137
Table 4.8: WS-* Specifications Supported by the ws2007HttpBinding
Binding 140
Table 4.9: ws2007HttpBinding Binding Properties 141
Table 4.10: wsDualHttpBinding Binding Properties 144
Table 4.11: netMsmqBinding Binding Properties 156
Table 4.12: msmqIntegrationBinding Binding Properties 166
Table 5.1: Combining InstanceContextMode and ConcurrencyMode 186
Table 5.2: Interaction of TransactionFlow elements 217
xxiii
Table 7.1: Settings for Enabling ASMX Features in a WCF Service 296
Table 7.2: Hosting Choices 312
Table 8.1: Client Authentication with Transport Security 328
Table 9.1: Tracing Source switchValue Options 380
Table 9.2: messageLogging Options 383
Table 12.1: netPeerTcpBinding Binding Properties 466
Table 13.1: URI Examples 505
Table 13.2: Common HTTP Verbs 506
Table 13.3: Web Programming Features in .NET Framework 3.5 508
Table A.1: ServiceThrottlingBehavior Properties 544

实例下载地址

WCF-Essential Windows Communication Foundation for .NET Framework 3.5.(2008)

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

发表评论

(您的评论需要经过审核才能显示)

查看所有0条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警