Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Microsoft Windows Communication Foundation 4.0 Cookbook for Developing SOA Applications
Microsoft Windows Communication Foundation 4.0 Cookbook for Developing SOA Applications

Microsoft Windows Communication Foundation 4.0 Cookbook for Developing SOA Applications: Over 85 easy recipes for managing communication between applications

eBook
€22.99 €32.99
Paperback
€41.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Table of content icon View table of contents Preview book icon Preview Book

Microsoft Windows Communication Foundation 4.0 Cookbook for Developing SOA Applications

Chapter 2. Endpoint, Binding, and Behavior

In this chapter, we will cover:

  • Configuring Default Endpoints

  • Setting up two-way communication over MSMQ

  • Building a Publish-Subscribe service with dual binding

  • Creating a multiple-endpoint service

  • Implementing a POX HTTP service

  • Defining a CustomBinding without a timestamp header

  • Suppressing mustUnderstand validation on unknown SoapHeaders

  • Sharing a physical address between multiple endpoints

Introduction


WCF services are exposed through service endpoints, which provide the basic access point for client to utilize the functionality offered by a given WCF service. Service endpoints consist of ABC and a set of behaviors. What is ABC? Well, A stands for Address, which tells service consumers “Where is the service?”, B stands for Binding, which describes “How to talk to the service?” and C stands for Contract, which shows “What functionality can the service provide?”

WCF provides plenty of built-in bindings (such as BasicHttpBinding, NetTcpBinding, NetMsmqBinding, and so on), which can help developers host service endpoints over various transport protocols. Behaviors also play an important role in WCF. By using behaviors, we can gain further manipulation over the WCF service at service or endpoint level.

This chapter provides eight recipes on using the built-in binding and behaviors to build various service endpoints, which represent some of the useful scenarios in general WCF service...

Configuring Default Endpoints


When programming with WCF, we will often need to create some simple WCF services for testing our ServiceContracts. These services often use very simple and typical endpoint and binding definitions. However, every time we need to set up such a service, we have to define the same endpoint and binding settings again and again, which really adds much duplicated work. Fortunately, WCF 4.0 introduces the Default Endpoint feature which saves us from defining common endpoint/binding settings repeatedly.

How to do it...

The steps for using a default endpoint are quite straightforward:

  1. Create a new Console Application project in Visual Studio 2010 targeting .NET Framework 4.0.

  2. Add the ServiceContract in the service project and implementation types we need in the service project. We can use any valid ServiceContract and its corresponding implementation class here. For example, the following IHelloService service containing a single SayHello operation is used in our sample...

Setting up two-way communication over MSMQ


For a long time, MSMQ has been a great message-based communication component on the Microsoft platform. And the Microsoft .NET framework has also provided managed programming interfaces for developers to develop distributed applications based on MSMQ. However, it is still a bit complicated and time consuming for developers to build a complete distributed service through the raw or encapsulated MSMQ programming interface. As the new unified communication development platform on Windows, WCF provides more convenient means for developing a distributed service over the underlying MSMQ component.

Getting ready

If you are not yet familiar with Microsoft Message Queuing (MSMQ), you can get useful information on the following site:

http://msdn.microsoft.com/en-us/library/ms711472(VS.85).aspx

Also, the MSDN library has provided detailed reference on the .NET Framework System.Messaging namespace that encapsulates the raw MSMQ programming interfaces (visit http...

Building a Publish-Subscribe service with dual binding


Publish-Subscribe is a common design pattern that is widely used in client/server communication applications. In WCF service development, the Publish-Subscribe pattern will also help in those scenarios where the service application will expose data to certain groups of clients that are interested in the service and the data is provided to clients as a push model actively (instead of polling by the client). This recipe will demonstrate how to implement the Publish-Subscribe pattern in a WCF service through dual binding.

Getting ready

The Publish-Subscribe pattern is widely adopted in various application development scenarios and there are many different kinds of descriptions for this pattern. Refer to the following links for more information:

How to do it...

To implement the Publish-Subscribe pattern, we need to...

Creating a multiple-endpoint service


For traditional distributed communication services, we will open the service over a certain transport-specific endpoint such as HTTP endpoint. If we need to expose it via another different transport layer, we will probably have to add additional code to implement the new endpoint. The WCF programming model separates the service implementation and underlying transport layer so that we can conveniently expose a single service implementation via multiple heterogeneous endpoints (with different a transport layer and binding configuration).

How to do it...

  1. First, we make sure our ServiceContract is ready for various endpoint bindings we want to use to expose it. Some bindings may have special requirements on ServiceContract (such as MSMQ-based bindings). The following sample contract is ready for most built-in bindings:

      [ServiceContract]
        public interface ICounterService
        {
            [OperationContract]
            void Increment();
    
            [OperationContract...

Implementing a POX HTTP service


WCF services by default use SOAP as the message format of service operations, which means each message transferred between the client and service is wrapped in a SOAP envelope that contains one SOAP body and some SoapHeaders. However, sometimes our WCF service will need to work with some legacy POX (Plain Old XML) clients or our WCF-based client will need to talk to some POX-style service. In such cases, it is necessary to let our WCF client or service generate arbitrary XML messages without strictly obeying the SOAP standard.

How to do it...

We will use a CustomBinding to build a POX-enabled WCF service and consume it with a POX-enabled WCF client program. Let’s have a look at the complete steps:

  1. The first thing to do is to make our ServiceContract POX ready. The following code shows a sample operation that is ready for exchanging POX-style messages.

      [OperationContract(Action=”*”,ReplyAction=”*”)]
             Message SayHello(Message reqMsg);

    Compared with normal...

Defining a CustomBinding without a timestamp header


For WCF bindings that use message-layer security, a timestamp header will be added in the SOAP envelope to ensure the timely delivery of the message so as to prevent a potential message-replaying attach. However, some non-WCF service platforms may not expose this header. When working with this kind of service client or service, we will need to prevent the WCF message engine from generating the timestamp header.

How to do it...

Using WSHttpBinding as an example, we can create a customized binding that derives most of the setting of the built-in WSHttpBinding (but suppresses the timestamp header generation).

The following code snippet demonstrates how to create the CustomBinding and configure the certain binding element to disable timestamp header generation.

private static Binding GetCustomHttpBinding()
{
   WSHttpBinding wshttp = new WSHttpBinding();
   var bec = wshttp.CreateBindingElements();

   SecurityBindingElement secbe = bec.Find&lt...

Suppressing mustUnderstand validation on unknown SoapHeaders


For a WCF service or client proxy, it is common to receive SoapHeaders within the coming request or returned response messages. SoapHeader has a mustUnderstand attribute that indicates to the target endpoint (or intermediate message processor) whether the SoapHeader must be processed. The following screenshot shows a typical SOAP message that contains a SoapHeader with the mustUnderstand attribute set to 1 (true).

Also for a XML Web Service or WCF service, we can dynamically insert SoapHeaders at runtime or statically apply them at design-time (which will be described via WSDL or service metadata).

By default, a WCF endpoint will perform validation on all the SoapHeaders within incoming messages, and if there are any unknown SoapHeaders (not predefined) which have a mustUnderstand attribute as 1 (or true), a validation exception will be raised by the runtime. However, sometimes it is useful to suppress this validation so that the...

Sharing a physical address between multiple endpoints


WCF supports exposing a single service through multiple heterogeneous endpoints. Another great feature is letting multiple endpoints listen over the same physical transport address. For example, you want to host a WCF service that has multiple endpoints exposed. However, you only have a single HTTP URL open for listening. Then you can use this feature to make all those endpoints (as long as they’re using the same transport protocol) listen on the same URL.

How to do it...

Our sample service will expose two endpoints (one is IFoo and the other is IBar) and both of them will listen on the same HTTP URL:

  1. The first thing we need to do is configure the service endpoints. We will still specify different values for the address attribute of the two endpoints. However, we will use a special attribute named listenUri to supply the physical address (identical for both endpoints). The following screenshot shows the usage of both attributes:

  2. It is also...

Left arrow icon Right arrow icon

Key benefits

  • Master WCF concepts and implement them in real-world environments
  • An example-packed guide with clear explanations and screenshots to enable communication between applications and services and make robust SOA applications
  • Resolve frequently encountered issues effectively with simple and handy recipes
  • Explore the new features of the latest .NET 4.0 framework/Visual Studio 2010

Description

The Windows Communication Foundation 4.0 (WCF 4.0) is a .NET-based application programming interface for building and running connected systems. It enables secure and reliable communication among systems within an organization or across the Internet. This book deals with the difficult issues faced by a .NET developer while working with WCF.WCF 4.0 is a communications infrastructure that unifies a broad array of distributed systems' capabilities in a composable, extensible architecture that supports multiple transports, messaging patterns, encodings, network topologies, and hosting models. This book is a collection of focused real-world recipes and covers basic recipes on topics such as working with contracts to more advanced topics such as extending WCF runtime. By the end of this book you will have valuable information that helps transform the potentially unproductive habits of .Net developers who work with WCF.This book will take you through many concepts starting with complete support for contract-related design for WCF service development. You will learn to use WCF's built-in feature for building various service endpoints. Service hosting and configuration are important areas for building WCF services, especially at the service deployment stage, and are detailed in this book. You will find it easy to work with WCF client proxy generation and metadata publishing and discovery when you go through recipes such as customizing auto-generated service proxies.The author then discusses the exchange of data in WCF service operation features, related to WCF data serialization. You will discover some useful tips for security in WCF service development and built-in features for developing concurrency control for your services built upon it.One big plus is that you will learn to extend the existing WCF framework to achieve advanced functionality. You will find a dedicated chapter for RESTful and AJAX-enabled service development. Moving on, you will find several useful WCF service interoperability cases, which are important for a distributed service development platform. Towards the end of this book you will find some handy and useful diagnostic methods for troubleshooting.

Who is this book for?

If you work with Windows Communication Foundation 4.0 and you want to be efficient when working with WCF features such as interoperability, proxy generation, and security, you will find this book very useful. With this book you will be able to find quick and handy solutions for various kinds of service development scenarios using Microsoft Windows Communication Foundation 4.0. To follow the recipes you will need to be comfortable with .NET Framework, C# programming, and the basics of SOA and how to develop them.

What you will learn

  • Share a physical address between multiple endpoints
  • Custom binding without a Timestamp header
  • Bind a WPF element with data from WCF service
  • Invoke a WCF service without blocking the front UI
  • Build a WCF service with ad hoc security mode
  • Intercept WCF operation messages with MessageInspector
  • Extend WCF security with custom AuthorizationManager
  • Build REST-style services with WCF
  • Call WCF services from AJAX script clients
Estimated delivery fee Deliver to Switzerland

Standard delivery 10 - 13 business days

€11.95

Premium delivery 3 - 6 business days

€16.95
(Includes tracking information)

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Oct 20, 2010
Length: 316 pages
Edition : 1st
Language : English
ISBN-13 : 9781849680769
Vendor :
Microsoft
Tools :

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Estimated delivery fee Deliver to Switzerland

Standard delivery 10 - 13 business days

€11.95

Premium delivery 3 - 6 business days

€16.95
(Includes tracking information)

Product Details

Publication date : Oct 20, 2010
Length: 316 pages
Edition : 1st
Language : English
ISBN-13 : 9781849680769
Vendor :
Microsoft
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 132.97
WCF 4.0 Multi-tier Services Development with LINQ to Entities
€41.99
Microsoft Windows Communication Foundation 4.0 Cookbook for Developing SOA Applications
€41.99
Applied Architecture Patterns on the Microsoft Platform
€48.99
Total 132.97 Stars icon

Table of Contents

13 Chapters
Working with Contracts Chevron down icon Chevron up icon
Endpoint, Binding, and Behavior Chevron down icon Chevron up icon
Hosting and Configuration Chevron down icon Chevron up icon
Service Discovery and Proxy Generation Chevron down icon Chevron up icon
Channel and Messaging Chevron down icon Chevron up icon
Dealing with Data in Service Chevron down icon Chevron up icon
Security Chevron down icon Chevron up icon
Concurrency Chevron down icon Chevron up icon
Extending WCF Runtime Chevron down icon Chevron up icon
RESTful and AJAX-enabled WCF Services Chevron down icon Chevron up icon
Interoperability Chevron down icon Chevron up icon
Diagnostics Chevron down icon Chevron up icon
Miscellaneous WCF Development Tips Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.8
(4 Ratings)
5 star 50%
4 star 25%
3 star 0%
2 star 0%
1 star 25%
Aykut Ucar Mar 22, 2011
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Short explanations and a quick sample after each explanation.For me, it is the perfect way of learning a concept.Examples are really detailed and make you understand what is going on behind.One of best tech books I read.
Amazon Verified review Amazon
C. JUNTAO Nov 10, 2010
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I've already had some WCF programming books. I think this one is an interesting and useful one as it is not focus on general WCF architecture or programming guideline, but provides many individual sample cases and tips about the questions or problems we might encounter. Also, I think it would be better if the book can add more advanced programming sample cases such as building a federation service or custom security token service.
Amazon Verified review Amazon
Assil Mar 31, 2013
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
Even though it is less than 300 pages, It touches so many great advanced topics that you cant find in other books.It highlights many important topics, gives clear examples and guides you to the references for more information.I liked it.I gave 4 stars for all the good things I wish It was even more comprehensive to cover all the WCF in 1000 pages.
Amazon Verified review Amazon
R. Kumar Sep 28, 2012
Full star icon Empty star icon Empty star icon Empty star icon Empty star icon 1
I am a senior .net developers for over 10 years now and I was looking for a book that can get me started with WCF however after start spending 7 days with it I can't even write a simple WCF service because I guess the book author expected everyone to be experienced WCF programmer. I believe a good book should always start from simple to advanced topics however here is totally opposite.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is the delivery time and cost of print book? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge? Chevron down icon Chevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries: www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges? Chevron down icon Chevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order? Chevron down icon Chevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact customercare@packt.com with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at customercare@packt.com using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy? Chevron down icon Chevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on customercare@packt.com with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on customercare@packt.com within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on customercare@packt.com who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on customercare@packt.com within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged? Chevron down icon Chevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use? Chevron down icon Chevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela