Best practices in WCF: Service design and performance guidelines (2024)

Best practices in WCF: Service design and performance guidelines (1)

byJoydip Kanjilal

Contributor

opinion

Jun 04, 20154 mins

Software Development

Take advantage of the recommended practices in WCF to build services that are responsive and can scale seamlessly over time

In this post I’ll present a discussion on WCF service design and performance guidelines and the recommended best practices. In future posts in this series of articles on WCF best practices, I’ll discuss other aspects like security, configuration, error handling, deployment, etc.

Design guidelines

You should separate service contracts from service implementation. You can also instantiate your WCF service using an IoC container to facilitate loose coupling. This approach would also allow you to inject configuration metadata to your service at runtime. You should decorate an interface using the ServiceContract attribute and refrain from specifying this attribute on a class, i.e., your service contracts should be interfaces and not classes.

You can manipulate the service headers to specify metadata like, culture, session data, etc. You should leverage the ServiceContract, DataContract, ServiceBehavior attributes to decorate your types and facilitate versioning of your service methods. You can use data transfer objects to exchange data back and forth between the service and the domain objects — you can take advantage of the adapter design pattern. It is also advisable to decouple the WCF configuration metadata from the web.config file to facilitate editing the WCF bindings, behaviors, etc. for each environment your service is supposed to work on.

Designing your service contract to accommodate future changes

I admit that change is inevitable, but with a proper plan and guidelines in place, incorporating and accommodating changes in your service layer is just seamless. You should use the Name, Namespace parameters on all contracts and also use the Order parameter on all the data members. If you would like to remove a service operation or update a service operation, refrain from changing the existing one — rather, create new ones.

Another preferred approach to manage changes to your service operations over time is to implement a message oriented design in each of your services. This implies that each of your WCF service methods would receive a message and also send out a message. The benefit of this approach is that when you need to update your service methods over time, you can still leverage this design — the future versions of your service implementation would not need a change in the service contract. In essence, you are not constrained to changing your service contract when a change request comes in as far as the design of your service contract is concerned. Any additional parameters you might need in your service methods may just be as simple as adding an optional parameter to the input message. Also, if your response message needs additional parameters, you can just add a few additional properties to the response message. This message driven design of your service contract would also facilitate backwards compatibility.

It is a good practice to use the async programming pattern when you are calling WCF services to ensure that your user interface can work in a non-blocking mode. It is a recommended practice to use RESTful services when you would like to build light-weight and scalable WCF services that would leverage the HTTP protocol. On the other hand if you would like to build a B2B application and you would like to take advantage of interoperability and also leverage the WCF’s capability of working on multiple protocols, SOAP is a good choice.

Performance guidelines

If your WCF service is hosted on IIS you can turn on IIS compression for static and dynamic content to improve performance. You can use the Windows Performance Monitor to analyse the performance bottlenecks. You can enable WCF performance counters by specifying the following in your web.config file.

<system.serviceModel>

<diagnostics performanceCounters="All" />

Take advantage of NetTCP binding to boost the throughput of your WCF services. Use light-weight data exchange formats, i.e., JSON in your WCF service to minimize the network traffic that your WCF service would otherwise need to consume if SOAP were used as a data exchange format. You should always use DataContract Serializer in lieu of XMLSerializer for better performance. You can also explore the possibilities of using binary serialization formats like MessagePack or Google’s Protocol Buffers to minimize the traffic even further.

You can also compress the data transferred over the wire to cut down on the network traffic between the service provider and the service consumers. Since there is no built in way to cache service responses in WCF, you can write custom code to cache service responses. You should set WCF service throttling and service configuration appropriately to improve service performance. I would discuss more on WCF service performance in the subsequent posts here. For now, you can take a look at this post for more information on the configuration thresholds.

Related content

  • how-toHow to use FastEndpoints in ASP.NET Core Take advantage of the free open-source FastEndpoints library to build fast and lean APIs in your ASP.NET Core applications. By Joydip KanjilalJul 11, 20247 minsMicrosoft .NETC#Development Libraries and Frameworks
  • how-toHow to use Refit to consume APIs in ASP.NET Core Take advantage of Refit REST library to simplify API consumption and make your code cleaner, more efficient, and easier to maintain.By Joydip KanjilalJul 04, 202410 minsC#Microsoft .NETSoftware Deployment
  • how-toWhen to use an abstract class vs. interface in C# Understanding the differences between an abstract class and interface is key to designing loosely coupled and extensible applications.By Joydip KanjilalJun 20, 202410 minsSmall and Medium BusinessMicrosoft .NETC#
  • how-to6 security best practices for ASP.NET Core Learn the best practices and built-in safeguards for preventing attacks and protecting sensitive data in your ASP.NET Core web applications. By Joydip KanjilalJun 07, 20246 minsC#Microsoft .NETWeb Development
  • Resources
  • Videos
Best practices in WCF: Service design and performance guidelines (2024)
Top Articles
NBA 2K23 Best Center Builds (Next-Gen/Current-Gen)
NBA 2K23 Best Small Forward (SF) Builds (Next-Gen/Current-Gen)
排期 一亩三分地
Pr 127 Seat Map
Health Stream Kaiser
Aarf Anchorage Alaska
104 Whiley Road Lancaster Ohio
15:30 Est
Wjbd Weather Radar
0.0Gomovies
Duralast Battery H6-Dl Group Size 48 680 Cca
Mayo Webscheduler
Westelm Order
National Weather Denver Co
Nalo Winds
Machiavelli ‑ The Prince, Quotes & The Art of War
Caribbean Mix Lake Ozark
Pritzker Sdn 2023
Www.burlingtonfreepress.com Obituaries
Budokai Z Pre Alpha Trello
Acuity Eye Group - La Quinta Photos
Best Chinese Rome Ny
How to Be an Extra in a Movie (and What to Expect)
Central Nj Craiglist
Spinning Gold Showtimes Near Mjr Westland Grand Cinema 16
Craigslist Swm
Bx9 Bus Schedule
I Wanna Dance With Somebody Showtimes Near St. Landry Cinema
Peloton Guide Stuck Installing Update
Roomba I3 Sealing Problem With Clean Base
Examination Policies: Finals, Midterms, General
Coil Cleaning Lititz
85085 1" Drive Electronic Torque Wrench 150-1000 ft/lbs. - Gearwrench
Rugged Gentleman Barber Shop Martinsburg Wv
Women On Twitch Go Without Makeup To Support A Fellow Streamer
Directions To 401 East Chestnut Street Louisville Kentucky
VMware accompagne ses partenaires et soutient leur transformation en faisant évoluer son programme « VMware Partner Connect » - Broadcom News & Stories - Français
Most Popular Pub food in Lipetsk, Lipetsk Oblast, Russia
فیلم 365 روز 1 نیکی مووی
Odawa Hypixel
Walmart Front Door Wreaths
Lenscrafters Westchester Mall
Bbc Weather In Mallorca
O'reilly's In Mathis Texas
Flixtor The Meg
11526 Lake Ave Cleveland Oh 44102
Sbc Workspace
Desi Cinemas.com
Dive Sports Bars Near Me
Edible Arrangements Track
Pnp Telegram Group
Twisted Bow Osrs Ge Tracker
Latest Posts
Article information

Author: Dr. Pierre Goyette

Last Updated:

Views: 6045

Rating: 5 / 5 (50 voted)

Reviews: 89% of readers found this page helpful

Author information

Name: Dr. Pierre Goyette

Birthday: 1998-01-29

Address: Apt. 611 3357 Yong Plain, West Audra, IL 70053

Phone: +5819954278378

Job: Construction Director

Hobby: Embroidery, Creative writing, Shopping, Driving, Stand-up comedy, Coffee roasting, Scrapbooking

Introduction: My name is Dr. Pierre Goyette, I am a enchanting, powerful, jolly, rich, graceful, colorful, zany person who loves writing and wants to share my knowledge and understanding with you.