Migrate WCF services to .NET Core gRPC
The following flavors of WCF service are supported:
- Basic request/reply services
- Full duplex services
- Session-based services
Basic request/reply services are the most straightforward and are migrated to equivalent gRPC unary services.
Duplex services are migrated to gRPC bidirectional streaming services, passing different messages over a persistent stream to represent the different operations from the WCF service. Both one-way and returning operations are supported in Duplex services.
Session-based services (that is, services which rely on a persistent server-side instance of
the service contract type, specified using
[OperationContract(SessionMode = SessionMode.Required)])
also use gRPC bidirectional streaming as this results in a persistent connection and the migrated
service contract can be instantiated and kept alive for the duration of the session.
You can read more about these different gRPC service types on the gRPC website.
Backward-compatible client libraries
Although the capabilities of gRPC can provide most of the same functionality as WCF, the implementation
is quite different. gRPC methods only take a single
message parameter, whereas WCF allowed multiple
parameters; in the migrated code, those parameters are used to define an equivalent message. Similarly,
WCF allowed primitive values such as
int to be returned from a method, while gRPC methods
can only return
message types. This means that consuming the gRPC service using the default generated
client stub could require substantial changes to your client code.
To help with this, Visual ReCode will generate a wrapper around the gRPC client that matches the interface
from your original WCF service. This wrapper is generated in a standalone class library project that
targets both .NET Standard 2.1, using the
Grpc.Net.ClientFactory package, and .NET 4.5,
using the older
Grpc package. You can distribute this class library to consumers of your service to make
it easier for them to migrate to your new gRPC service.
The client wrapper for Duplex services even takes care of mapping messages from the stream to the callback contract interface implementation, and transparently handles returned values from duplex operations.
Consistent project structure
Your WCF solution likely consists of multiple projects, carefully organized over the years. Visual ReCode will maintain this project structure in the generated solution, keeping naming, directories, namespaces, references and everything else so that everything will be where you expect it to be. However, only types that are actually required by the migrated service will be copied across, making your new solution clean and tidy.
If you tried our preview releases, you’ll know that you had to run through the wizard every time you
ran the migration. With the 1.0 release, the wizard will save a
.recode file into a
solution folder in the source solution. These files come with a custom designer view that allows you
to re-run the migration with a single button click. You can check these files into source control so
that anybody on your team who has the extension installed can run the migration.
Migrate multiple services to a single solution
Based on customer feedback, we have added the ability to include more than one WCF service in a migration, targeting a single new solution. Each service is migrated to a separate ASP.NET Core gRPC project to minimize complexity in the generated code.
Protobuf does not have a native type that is equivalent to C#’s
decimal; only floating-point types are provided.
For financial applications or anything that requires perfect precision, we know this is unacceptable. So Visual ReCode
will now add a custom
DecimalValue type to any converted application that uses
decimal values in its contracts.
This custom type is provided as a
decimal_value.proto file included in the generated project, along with a C# implementation
that handles implicit conversion to the native
decimal type. You can read more about our decimal implementation
in this blog post.
Migration reports and TODO comments
Every time a migration is run it generates a helpful HTML report with information about which types and files were copied and generated, and highlighting any potential issues with the new solution.
In cases where fully-automated migration was not possible (for example, WCF methods with
Visual ReCode adds
// TODO comments to the generated code to make it easier for you to find and fix those problems
using the Visual Studio Task List.
We’re not done yet!
WCF is a big, complicated framework and we know Visual ReCode doesn’t handle everything yet. We think it’s capable enough to succeed for lots of people and projects, so we’re putting it out there to get you started. If you try it out and run into something in your solution(s) that the tool doesn’t understand or migrate properly, please let us know so we can work with you to try and find a solution.
In terms of future development, we’re already working on support for migrating WCF request/reply services to
ASP.NET Core Web APIs. We aim to support WCF
applications that were using Basic HTTP Binding with SOAP messages, as well as the WCF ReST extensions
[WebInvoke] attributes. The migrated projects will include
Swagger™/OpenAPI support and, just like our gRPC projects, we’ll provide a backward-compatible
client wrapper to make the transition easier for your service consumers.