Visual ReCode supports migrating the following types of WCF service to .NET Core gRPC:
Basic Request/Reply Services
These are the simplest WCF services, which might use basic HTTP binding and SOAP messages, and consist of operations which accept and return data with no persistent connection or server-side sessions. These services can be migrated to simple gRPC request/reply services that work in much the same way, except gRPC will use Protobuf for the messages and HTTP/2 as the connection protocol.
Duplex services
WCF Duplex services create a persistent connection between the client and server, and messages can be sent by either end independently. In WCF these services are created using a pair of interfaces: the service contract interface that specifies the server methods the client can invoke, and a callback contract interface that defines the client methods the server can invoke.
gRPC supports persistent, two-way message passing using bidirectional streams. These provide similar functionality to duplex services but with different semantics. Instead of specifying methods that the client and server can invoke on each other, a stream allows different messages to be sent back and forth. For duplex services, Visual ReCode generates a bidirectional streaming service with different messages for each of the WCF operation methods, and maps these to the service contract or callback contract from your original application code.
Here is the familiar Calculator example from WCF:
[ServiceContract(SessionMode = SessionMode.Required,
CallbackContract = typeof(ICalculatorCallback))]
public interface ICalculatorDuplex
{
[OperationContract(IsOneWay = true)]
void Clear();
void Add(double value);
void Subtract(double value);
void MultiplyBy(double value);
void DivideBy(double value);
}
public interface ICalculatorCallback
{
void Result(double value);
}
For these contracts, Visual ReCode will generate a Protobuf file something like this:
service CalculatorDuplex {
rpc Start (stream CalculatorDuplexAction) returns (stream CalculatorDuplexCallback);
}
message CalculatorDuplexAction {
message Clear { }
message Add {
double value = 1;
}
// ...
oneof action {
Clear clear = 1;
Add add = 2;
// ...
}
}
message CalculatorDuplexCallback {
message Result {
double value = 1;
}
oneof callback {
Result result = 1;
}
}
“Session Required” Services
Some WCF services rely on a persistent instance of the Service Contract object on the server for each connected client. There is no direct correlation for this in gRPC, but by using the same streaming approach as the Duplex migration we are able to achieve the same effect. The gRPC stream protocol forces the service instance to remain active for as long as the stream is alive, and even makes sure that traffic is all routed to the same instance in load-balanced situations.