ServiceWire 是一款速度快、重量轻的服务主机和动态客户端库,可简化高性能远程过程的开发和使用。
ServiceWire lets one .NET process call an interface implemented in another .NET process, over named pipes or TCP/IP, as if it were local. You write a plain C# interface and implement it once. There is no IDL, no code generator, no attributes and no build step — the client proxy is emitted at runtime from the interface you already have.
Full documentation with worked samples: getting started · contracts · transports · serialization · security · logging · interception · wire protocol · performance · migrating to 7.0 · troubleshooting
Reading this on NuGet? The guide is at
dotnet add package ServiceWireTargets netstandard2.0 and net8.0. NuGet package.
// 1. A contract both processes reference
public interface IMath
{
int Add(int a, int b);
}
// 2. An implementation, hosted as a singleton
public class MathService : IMath
{
public int Add(int a, int b) => a + b;
}
// 3. A host
using var host = new TcpHost(8098);
host.AddService(new MathService());
host.Open();
// 4. A client
using var client = new TcpClient(new TcpEndPoint(new IPEndPoint(IPAddress.Loopback, 8098)));
int sum = client.Proxy.Add(2, 3); // 5Swap TcpHost/TcpClient for NpHost/NpClient and the same code runs over a named pipe.
Step-by-step, including the project layout and how to run it: Getting started.
ServiceWire's dynamically generated proxy will not run as x86 on an x64 system. This usually bites when Visual Studio's console template leaves Prefer 32-bit enabled. Choose AnyCPU or the specific target so you do not run 32-bit under WOW64 on an x64 machine.
out and ref parameters (except non-primitive value types)ISerializer) and compression (ICompressor)ILog, IStats)TcpHost and NpHost expose their listener lifecycle through the inherited Status property: Created, Opening, Open, Faulted, Closed. This reports listener state, not the state of an individual client connection.
if (host.Status == HostStatus.Faulted)
{
// Create and open a replacement host, or otherwise recover the listener.
}See Logging and diagnostics for a supervisor pattern.
Portions of this library (the dynamic proxy) are derived from RemotingLite by Frank Thomsen. Licensed under the terms in License.txt.
The older project wiki is kept for historical reference; the user guide supersedes it.
A major performance release. Steady-state calls are 43–70% faster than 6.0.1 on named pipes and 13–47% faster on TCP; TCP connection setup is roughly 14× faster on .NET 8 and 10. Full tables: Performance.
Both mixed-version pairings — 6.x client with 7.0 server, and 7.0 client with 6.x server — keep working over the classic v1 wire path. The new v2 wire activates only when both ends are 7.0, so a fleet can be upgraded in any order. See Migrating to 7.0.
Internal optimizations (v1 wire format unchanged, proven byte-identical by golden tests):
Type.GetType lookups in DefaultSerializer.BufferedStream, collapsing dozens of per-field pipe syscalls per call into one (and fixing a pipe stream that was never disposed).Socket.NoDelay on client and accepted sockets to eliminate Nagle and delayed-ACK latency; both sides already buffer and flush once per message.MethodInfo.Invoke (byref methods fall back to reflection); async results through compiled Task.Result getters; client Task.FromResult wrapping through compiled converters. Client-visible exception behavior is unchanged and covered by parity tests.CompressionLevel.Fastest in the default compressor, and reused ZK cipher instances (identical ciphertext).Multi-targeting: the package now ships netstandard2.0 (unchanged 6.x dependency graph, so no new binding redirects for .NET Framework consumers) and net8.0 (no package dependencies, plus span-based fast paths that produce identical wire bytes).
Bug fixes:
string[] above the compression threshold was written with a type code no receiver could decode; it now uses CompressedUnknown, which every release since 1.5.0 can read.Type parameters crashed the default serializer; they now use the wire format's Type code.TargetSite), which killed the connection whenever a service method threw with the default serializer; a converter now preserves the exception type, message, HResult, inner chain, and server stack trace.Socket.ConnectAsync and waited on its completion callback, which .NET dispatches as a thread-pool work item. An application whose pool was saturated could therefore see TimeoutException from new TcpClient(...) against a server that was listening the whole time, more often the fewer cores the machine had. The connect now completes on the calling thread, so ConnectTimeOutMs measures the network alone. Named pipes were never affected.TcpClient(IPEndPoint) now routes through TcpEndPoint, so its connect timeout comes from one place instead of a hard-coded literal; pass a TcpEndPoint to choose your own.Wire protocol v2 — the default on both transports, negotiated, never sent to a 6.x peer. Frame layouts and rationale: Wire protocol.
ServiceSyncInfo.CapabilityFlags member (tolerant serializers on 6.x clients ignore it; a strict custom ISerializer on a 6.x client may need updating — this is part of why this release is a major version).MethodInvocation2/Response2 messages with length prefixes and correlation ids: a request payload that fails to decode is answered with a correlated error response instead of desynchronizing the stream and killing the connection.DateTime values travel as ToBinary() (Kind-preserving, no string parsing).Host.EnableWireV2 = false (before AddService) for all clients of a host, and TcpEndPoint.UseWireV2 = false / NpEndPoint.UseWireV2 = false per client.Opt-in additions (defaults preserve prior behavior): TCP receive/send timeouts on TcpEndPoint and TcpHost, and a persistent log file writer via LoggerBase.PersistentFileWriter.
A new interop test matrix runs the published ServiceWire 6.0.1 package as a separate process against 7.0 in both directions across TCP and named pipes, with and without compression, in CI.
SocketAsyncEventArgs after connection attempts (#90).Host.Status property and HostStatus lifecycle states so applications can detect listener failures (#83).System.String[] (#82).Type.IsAssignableFrom. Many thanks to IvoTops for contributing this fix in pull request #98.暂无开放 Issues,或尚未同步最近议题。