For readers who want to have a deep understanding of WCF's message exchange, Tcptracer is definitely a great tool. We place tcptracer between service and service agents, and Tcptracer will help us to receive, display, and forward messages that flow through him.
Essentially, Tcptracer is a router. When we start, we need to set two ports: the original port (source ports) and the destination port (destination ports), then Tcptracer will be on the original port for network monitoring. Once the request arrives, he intercepts the entire requested message and displays the entire message to the message panel. Tcptracer then sends the message to the destination port intact. On the other hand, messages sent from the destination port to the original port are also intercepted, displayed, and forwarded by the Tcptracer.
Next we'll show you how to route messages through Tcptracer in WCF through the following steps.
Step one, create a simple WCF application
In order to demonstrate the application of tcptracer in WCF, we need to create a simple application for WCF services, for which we create an example of a simple computing service.
The entire application uses the four-tier structure as shown in the following figure: contracts, Services, hosting, and clients.
Contracts:class Library project, defines all contracts, including service contracts, data contracts, message contracts, and error contracts, which are referenced by three other projects at the same time
Services:class Library project, which implements the service contract defined in contracts
Hosting: Console project, referencing both contracts and services, to implement a boarding service for a serviced project
Clients: Console project, referencing contracts, impersonating the caller of the service
Service Contract: Artech.TcpTraceDemo.Contracts.ICalculate
//---------------------------------------------------------------
// EndpointAddress & WCF Addressing (c) by 2008 Jiang Jin Nan
//---------------------------------------------------------------
using System.ServiceModel;
namespace Artech.TcpTraceDemo.Contracts
{
[ServiceContract]
public interface ICalculate
{
[OperationContract]
double Add(double x, double y);
}
}