Test in production without watermarks.
Works wherever you need it to.
Get 30 days of fully functional product.
Have it up and running in minutes.
Full access to our support engineering team during your product trial
Using the JSON-RPC protocol, StreamJsonRpc in C# enables effective communication between clients and servers across various transport levels. With the help of this library, remote procedure calls can be implemented more easily, allowing developers to create reliable distributed systems in which programs can call methods on distant servers just like they would locally. By allowing dynamic PDF creation based on data transferred through JSON-RPC requests, StreamJsonRpc improves application capabilities when used with IronPDF, a complete .NET Framework for PDF generation and manipulation. For developers looking to streamline the process of creating customized reports, invoices, or any document-centric application that needs to generate PDFs on demand, this interface is quite helpful.
IronPDF gives developers flexibility and efficiency in organizing and delivering content by supporting the conversion of HTML, ASPX, and raw data into high-quality PDF publications. StreamJsonRpc and IronPDF work together to enable C# developers to build responsive, scalable apps that easily combine complex PDFs with remote procedure calls.
StreamJsonRpc is a cross-platform library designed for facilitating remote procedure calls (RPC) using a lightweight and efficient wire protocol. It utilizes an underlying transport mechanism that supports various communication channels such as TCP/IP, named pipes, and HTTP. The library leverages .NET events for handling incoming requests and responses, providing a robust mechanism for asynchronous communication. Developers can attach method implementations to handle RPC requests and define custom behaviors using the StreamJsonRpc API. StreamJsonRpc is available as a .NET Portable Library, ensuring compatibility across different platforms and enabling seamless integration into diverse .NET applications.
A strong support for bidirectional communication, including notifications and progress reporting, is one of StreamJsonRpc's key characteristics. By supporting various transport protocols including HTTP, Named Pipes, and TCP/IP, it gives programs more communication options. JSON-RPC message serialization and deserialization are handled by StreamJsonRpc, guaranteeing compatibility across many platforms and JSON-supporting computer languages.
StreamJsonRpc was designed with performance and extensibility in mind. It is compatible with existing C# programs and may be used to construct client-server applications, microservices architectures, distributed systems, and other applications where dependable and efficient communication is crucial. When integrating remote procedure calls into C# projects, developers tend to choose it because of its dependability and ease of use.
A comprehensive collection of functionality is provided by C#'s StreamJsonRpc, which is intended to facilitate and improve JSON-RPC protocol-based client-server application communication.
By considering remote operations as though they were local function calls, StreamJsonRpc enables clients to call methods on a server via remote procedure calls. By disguising the intricacies of network communication, this abstraction makes the creation of distributed applications easier.
Bidirectional client-server communication is supported by the library. Real-time communication and updates are made possible by the ability for clients to submit requests to servers, which in turn can reply with notifications or results.
Because it is transport layer agnostic, StreamJsonRpc can function over a variety of transport protocols, including HTTP, Named Pipes, and TCP/IP. Because of this adaptability, developers can select the best transport method according to the needs of their applications and the network settings.
It manages JSON-RPC message serialization and deserialization, guaranteeing smooth communication across various platforms and JSON-capable computer languages.
Progress reporting techniques are supported by StreamJsonRpc for long-running activities. This feature improves user experience and transparency by enabling servers to update clients on the status of current processes.
To handle exceptions and problems that arise during the invocation of remote methods, the library has extensive error-handling features. This guarantees dispersed systems' resilience and dependability.
StreamJsonRpc can be extended by developers to alter its functionality or include it with already existing application architectures. Because of its versatility, it may be tailored to meet a variety of integration needs and application scenarios.
Through effective custom message handling and transport layer management, StreamJsonRpc maximizes throughput in client-server communication while guaranteeing low overhead.
Through the use of asynchronous operations, it enables applications to achieve improved responsiveness and scalability. It completely supports asynchronous communication patterns.
Through conformance to the JSON-RPC standard, StreamJsonRpc facilitates smooth integration in diverse contexts by fostering interoperability between C# applications and services built in other languages that support JSON.
Along with these main features, there are some bonus features past the JSON-RPC spec which include features such as support for compact binary serialization and dynamic client proxy.
A client and a server must be set up in order to create and configure StreamJsonRpc in a C# application. The detailed instructions for each part are provided below:
First, make sure your .NET project is ready. You can create a new one with Visual Studio or the .NET CLI.
dotnet new console -n StreamjsonrpcExample
cd StreamjsonrpcExample
dotnet new console -n StreamjsonrpcExample
cd StreamjsonrpcExample
To implement JSON-RPC communication, install the StreamJsonRpc package from NuGet. It contains the necessary libraries.
dotnet add package StreamJsonRpc
dotnet add package StreamJsonRpc
Make a class that will act as the server for JSON-RPC. Observe this simple example:
using Microsoft.AspNetCore.Hosting;
using StreamJsonRpc;
using System;
using System.Threading.Tasks;
public class MyService
{
// Asynchronous method to add two integers
public Task<int> AddAsync(int a, int b)
{
return Task.FromResult(a + b);
}
// Asynchronous method to greet a user
public Task<string> GreetAsync(string name)
{
return Task.FromResult($"Hello, {name}!");
}
}
class Program
{
static void Main(string[] args)
{
// Initialize the service offering RPC methods
var service = new MyService();
// Create a StreamJsonRpc server listening on websockets
var jsonRpc = new JsonRpc(new ServerWebSocketJsonRpcMessageHandler("ws://localhost:8080"));
// Add service as RPC target
jsonRpc.AddLocalRpcTarget(service);
// Start listening for incoming JSON-RPC requests
jsonRpc.StartListening();
Console.WriteLine("JsonRpc server listening on ws://localhost:8080");
Console.WriteLine("Press any key to stop the server...");
// Wait for user input to stop the server
Console.ReadKey();
// Dispose resources when done
jsonRpc.Dispose();
}
}
using Microsoft.AspNetCore.Hosting;
using StreamJsonRpc;
using System;
using System.Threading.Tasks;
public class MyService
{
// Asynchronous method to add two integers
public Task<int> AddAsync(int a, int b)
{
return Task.FromResult(a + b);
}
// Asynchronous method to greet a user
public Task<string> GreetAsync(string name)
{
return Task.FromResult($"Hello, {name}!");
}
}
class Program
{
static void Main(string[] args)
{
// Initialize the service offering RPC methods
var service = new MyService();
// Create a StreamJsonRpc server listening on websockets
var jsonRpc = new JsonRpc(new ServerWebSocketJsonRpcMessageHandler("ws://localhost:8080"));
// Add service as RPC target
jsonRpc.AddLocalRpcTarget(service);
// Start listening for incoming JSON-RPC requests
jsonRpc.StartListening();
Console.WriteLine("JsonRpc server listening on ws://localhost:8080");
Console.WriteLine("Press any key to stop the server...");
// Wait for user input to stop the server
Console.ReadKey();
// Dispose resources when done
jsonRpc.Dispose();
}
}
Imports Microsoft.AspNetCore.Hosting
Imports StreamJsonRpc
Imports System
Imports System.Threading.Tasks
Public Class MyService
' Asynchronous method to add two integers
Public Function AddAsync(ByVal a As Integer, ByVal b As Integer) As Task(Of Integer)
Return Task.FromResult(a + b)
End Function
' Asynchronous method to greet a user
Public Function GreetAsync(ByVal name As String) As Task(Of String)
Return Task.FromResult($"Hello, {name}!")
End Function
End Class
Friend Class Program
Shared Sub Main(ByVal args() As String)
' Initialize the service offering RPC methods
Dim service = New MyService()
' Create a StreamJsonRpc server listening on websockets
Dim jsonRpc As New JsonRpc(New ServerWebSocketJsonRpcMessageHandler("ws://localhost:8080"))
' Add service as RPC target
jsonRpc.AddLocalRpcTarget(service)
' Start listening for incoming JSON-RPC requests
jsonRpc.StartListening()
Console.WriteLine("JsonRpc server listening on ws://localhost:8080")
Console.WriteLine("Press any key to stop the server...")
' Wait for user input to stop the server
Console.ReadKey()
' Dispose resources when done
jsonRpc.Dispose()
End Sub
End Class
MyService Class: Specifies the methods that the client can call remotely, such as AddAsync
and GreetAsync
.
This starts a new JsonRpc
instance, initializes MyService
, and configures a WebSocket message handler to listen at ws://localhost:8080
. The server exposes MyService
as a new local RPC target and begins to wait for JSON-RPC queries to arrive. Press a key to stop listening and discard resources.
Make a class that will function as the client for JSON-RPC. Observe this simple example:
using StreamJsonRpc;
using System;
using System.Threading.Tasks;
class Program
{
static async Task Main(string[] args)
{
// Create a JSON-RPC client connected to the WebSocket server endpoint
var proxy = new JsonRpc(new ClientWebSocketJsonRpcMessageHandler("ws://localhost:8080"));
// Start listening for incoming messages from the server
await proxy.StartListeningAsync();
// Invoke the AddAsync method on the server
var resultAdd = await proxy.InvokeAsync<int>("AddAsync", 10, 20);
Console.WriteLine($"AddAsync result: {resultAdd}");
// Invoke the GreetAsync method on the server
var resultGreet = await proxy.InvokeAsync<string>("GreetAsync", "John");
Console.WriteLine($"GreetAsync result: {resultGreet}");
// Dispose the proxy when done
proxy.Dispose();
}
}
using StreamJsonRpc;
using System;
using System.Threading.Tasks;
class Program
{
static async Task Main(string[] args)
{
// Create a JSON-RPC client connected to the WebSocket server endpoint
var proxy = new JsonRpc(new ClientWebSocketJsonRpcMessageHandler("ws://localhost:8080"));
// Start listening for incoming messages from the server
await proxy.StartListeningAsync();
// Invoke the AddAsync method on the server
var resultAdd = await proxy.InvokeAsync<int>("AddAsync", 10, 20);
Console.WriteLine($"AddAsync result: {resultAdd}");
// Invoke the GreetAsync method on the server
var resultGreet = await proxy.InvokeAsync<string>("GreetAsync", "John");
Console.WriteLine($"GreetAsync result: {resultGreet}");
// Dispose the proxy when done
proxy.Dispose();
}
}
Imports StreamJsonRpc
Imports System
Imports System.Threading.Tasks
Friend Class Program
Shared Async Function Main(ByVal args() As String) As Task
' Create a JSON-RPC client connected to the WebSocket server endpoint
Dim proxy = New JsonRpc(New ClientWebSocketJsonRpcMessageHandler("ws://localhost:8080"))
' Start listening for incoming messages from the server
Await proxy.StartListeningAsync()
' Invoke the AddAsync method on the server
Dim resultAdd = Await proxy.InvokeAsync(Of Integer)("AddAsync", 10, 20)
Console.WriteLine($"AddAsync result: {resultAdd}")
' Invoke the GreetAsync method on the server
Dim resultGreet = Await proxy.InvokeAsync(Of String)("GreetAsync", "John")
Console.WriteLine($"GreetAsync result: {resultGreet}")
' Dispose the proxy when done
proxy.Dispose()
End Function
End Class
This example establishes a connection to ws://localhost:8080
to start a JsonRpc
instance with a WebSocket message handler. It then enables the AddAsync
and GreetAsync
methods that are defined on the server (MyService
) by establishing a connection with the JSON-RPC server. Finally, it shows the outcomes that the server has returned and releases the resources after the RPC calls are finished.
PDF pages can be dynamically generated in C# applications by integrating StreamJsonRpc with IronPDF and using the data exchanged via JSON-RPC queries. This is a basic how-to for setting up IronPDF and StreamJsonRpc:
IronPDF can be used by C# programs to create, read, and edit PDF documents. This tool makes it simple for developers to convert HTML, CSS, and JavaScript information into print-ready, high-quality PDFs. Among the crucial tasks are adding headers and footers, dividing and merging PDFs, watermarking documents, and converting HTML to PDF. IronPDF is helpful for a variety of applications because it supports both .NET Framework and .NET Core.
Because PDFs are easy to use and offer a plethora of content, developers may easily integrate them into their products. Because IronPDF can handle complex layouts and formatting with ease, the output PDFs it generates nearly match the original HTML text.
PDF Generation from HTML
Convert JavaScript, HTML, and CSS to PDF. IronPDF supports media queries and responsive design, two contemporary web standards. It is a useful tool for dynamically decorating PDF documents, reports, and bills using HTML and CSS.
PDF Editing
Pre-existing PDFs can have text, photos, and other content added to them. Take text and images out of PDF files. Developers can combine numerous PDFs into one file, or divide PDF files into multiple separate papers. Include watermarks, annotations, headers, and footers.
PDF Conversion
It is possible to convert a variety of file formats, including Word, Excel, and image files, to PDF using IronPDF. With it, you can also carry out PDF-to-image conversion (PNG, JPEG, etc.).
Performance and Reliability
High performance and dependability are desired design qualities in industrial settings. IronPDF manages large document sets with ease.
To gain the tools you need to work with PDFs in .NET projects, install the IronPDF package.
dotnet add package IronPdf
dotnet add package IronPdf
Provide methods in the service class PdfService.cs
that will create PDFs from the data that is received. As an illustration:
using IronPdf;
using System.IO;
using System.Threading.Tasks;
public class PdfService
{
// Asynchronously generates a PDF from HTML content
public async Task<byte[]> GeneratePdfAsync(string htmlContent)
{
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf(htmlContent);
return await pdf.BinaryDataAsync();
}
}
using IronPdf;
using System.IO;
using System.Threading.Tasks;
public class PdfService
{
// Asynchronously generates a PDF from HTML content
public async Task<byte[]> GeneratePdfAsync(string htmlContent)
{
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf(htmlContent);
return await pdf.BinaryDataAsync();
}
}
Imports IronPdf
Imports System.IO
Imports System.Threading.Tasks
Public Class PdfService
' Asynchronously generates a PDF from HTML content
Public Async Function GeneratePdfAsync(ByVal htmlContent As String) As Task(Of Byte())
Dim renderer = New ChromePdfRenderer()
Dim pdf = renderer.RenderHtmlAsPdf(htmlContent)
Return Await pdf.BinaryDataAsync()
End Function
End Class
Use Program.cs
as the interface on the server for StreamJsonRpc to offer the GeneratePdfAsync
method over a stream JSON-RPC:
using StreamJsonRpc;
using System;
using System.Net.WebSockets;
using System.Threading.Tasks;
class Program
{
static async Task Main(string[] args)
{
// Initialize PdfService which generates PDFs
var service = new PdfService();
// Create JSON-RPC server listening on websockets
var jsonRpc = new JsonRpc(new WebSocketRpcServerMessageHandler(new Uri("ws://localhost:8080")));
// Add the PdfService as an RPC target
jsonRpc.AddLocalRpcTarget(service);
// Start listening for incoming JSON-RPC requests
jsonRpc.StartListening();
Console.WriteLine("JsonRpc server listening on ws://localhost:8080");
Console.WriteLine("Press any key to stop the server...");
// Wait for user input to stop the server
Console.ReadKey();
// Gracefully stop listening and dispose resources when done
await jsonRpc.StopListeningAsync();
jsonRpc.Dispose();
}
}
using StreamJsonRpc;
using System;
using System.Net.WebSockets;
using System.Threading.Tasks;
class Program
{
static async Task Main(string[] args)
{
// Initialize PdfService which generates PDFs
var service = new PdfService();
// Create JSON-RPC server listening on websockets
var jsonRpc = new JsonRpc(new WebSocketRpcServerMessageHandler(new Uri("ws://localhost:8080")));
// Add the PdfService as an RPC target
jsonRpc.AddLocalRpcTarget(service);
// Start listening for incoming JSON-RPC requests
jsonRpc.StartListening();
Console.WriteLine("JsonRpc server listening on ws://localhost:8080");
Console.WriteLine("Press any key to stop the server...");
// Wait for user input to stop the server
Console.ReadKey();
// Gracefully stop listening and dispose resources when done
await jsonRpc.StopListeningAsync();
jsonRpc.Dispose();
}
}
Imports StreamJsonRpc
Imports System
Imports System.Net.WebSockets
Imports System.Threading.Tasks
Friend Class Program
Shared Async Function Main(ByVal args() As String) As Task
' Initialize PdfService which generates PDFs
Dim service = New PdfService()
' Create JSON-RPC server listening on websockets
Dim jsonRpc As New JsonRpc(New WebSocketRpcServerMessageHandler(New Uri("ws://localhost:8080")))
' Add the PdfService as an RPC target
jsonRpc.AddLocalRpcTarget(service)
' Start listening for incoming JSON-RPC requests
jsonRpc.StartListening()
Console.WriteLine("JsonRpc server listening on ws://localhost:8080")
Console.WriteLine("Press any key to stop the server...")
' Wait for user input to stop the server
Console.ReadKey()
' Gracefully stop listening and dispose resources when done
Await jsonRpc.StopListeningAsync()
jsonRpc.Dispose()
End Function
End Class
To connect to the server and request the creation of a PDF, implement the StreamJsonRpc client (ClientProgram.cs
):
using StreamJsonRpc;
using System;
using System.Net.WebSockets;
using System.Text;
using System.Threading.Tasks;
using System.IO;
class ClientProgram
{
static async Task Main(string[] args)
{
// Create JSON-RPC client connected to WebSocket server endpoint
var proxy = new JsonRpc(new WebSocketRpcClientMessageHandler(new Uri("ws://localhost:8080")));
// Start listening for incoming messages from the server
await proxy.StartListeningAsync();
// Example HTML content
string htmlContent = "<html><body><h1>Hello, IronPDF!</h1></body></html>";
// Invoke GeneratePdfAsync method on the server
var pdfBytes = await proxy.InvokeAsync<byte[]>("GeneratePdfAsync", htmlContent);
// Save the resulted PDF to a file
File.WriteAllBytes("GeneratedPdf.pdf", pdfBytes);
Console.WriteLine("PDF generated: GeneratedPdf.pdf");
// Dispose the proxy when done
proxy.Dispose();
}
}
using StreamJsonRpc;
using System;
using System.Net.WebSockets;
using System.Text;
using System.Threading.Tasks;
using System.IO;
class ClientProgram
{
static async Task Main(string[] args)
{
// Create JSON-RPC client connected to WebSocket server endpoint
var proxy = new JsonRpc(new WebSocketRpcClientMessageHandler(new Uri("ws://localhost:8080")));
// Start listening for incoming messages from the server
await proxy.StartListeningAsync();
// Example HTML content
string htmlContent = "<html><body><h1>Hello, IronPDF!</h1></body></html>";
// Invoke GeneratePdfAsync method on the server
var pdfBytes = await proxy.InvokeAsync<byte[]>("GeneratePdfAsync", htmlContent);
// Save the resulted PDF to a file
File.WriteAllBytes("GeneratedPdf.pdf", pdfBytes);
Console.WriteLine("PDF generated: GeneratedPdf.pdf");
// Dispose the proxy when done
proxy.Dispose();
}
}
Imports StreamJsonRpc
Imports System
Imports System.Net.WebSockets
Imports System.Text
Imports System.Threading.Tasks
Imports System.IO
Friend Class ClientProgram
Shared Async Function Main(ByVal args() As String) As Task
' Create JSON-RPC client connected to WebSocket server endpoint
Dim proxy = New JsonRpc(New WebSocketRpcClientMessageHandler(New Uri("ws://localhost:8080")))
' Start listening for incoming messages from the server
Await proxy.StartListeningAsync()
' Example HTML content
Dim htmlContent As String = "<html><body><h1>Hello, IronPDF!</h1></body></html>"
' Invoke GeneratePdfAsync method on the server
Dim pdfBytes = Await proxy.InvokeAsync(Of Byte())("GeneratePdfAsync", htmlContent)
' Save the resulted PDF to a file
File.WriteAllBytes("GeneratedPdf.pdf", pdfBytes)
Console.WriteLine("PDF generated: GeneratedPdf.pdf")
' Dispose the proxy when done
proxy.Dispose()
End Function
End Class
The PdfService.cs
class is a fundamental part of a StreamJsonRpc server implementation that makes it easier for a C# application to generate PDF documents using IronPDF. By utilizing IronPDF's RenderHtmlAsPdf
, this service class contains methods for handling the conversion of HTML material into PDF format. HTML content is accepted as input via the GeneratePdfAsync
method, which is designated as asynchronous (async Task<byte[]> GeneratePdfAsync(string htmlContent)
).
This method creates an instance of ChromePdfRenderer
to carry out the conversion, producing a PDF document with RenderHtmlAsPdf(htmlContent)
. The created PDF's binary data is then retrieved asynchronously by the method (pdf.BinaryDataAsync()
), which subsequently returns the data as a byte[]
array.
This method guarantees quick and responsive PDF generation, making it appropriate for applications that need to create documents quickly. The PDF generation logic is contained in PdfService.cs
, which makes it simple for developers to integrate and expose this functionality over StreamJsonRpc. This allows distant clients to smoothly invoke PDF generation jobs while preserving the modularity and clarity of their server-side design.
To sum up, developers may create reliable and effective .NET apps that support remote procedure calls (RPC) and make use of strong PDF production capabilities by combining StreamJsonRpc with IronPDF. Using JSON-RPC, a lightweight protocol for remote procedure calls, StreamJsonRpc enables smooth communication between client and server components. Developers can use this in conjunction with IronPDF to generate dynamic, data-driven PDFs that are dependent on the outcomes of these remote calls.
When preparing reports, invoices, or any other document that must represent the most recent data available, this integration is very helpful as it allows for real-time data retrieval and PDF output. The integration of these technologies optimizes the development process, boosts performance, and strengthens the application's capacity to effectively satisfy intricate business needs.
With IronPDF and the Iron Software Development Tools, developers can create more web apps and features more quickly, all for a starting price of $749. It accomplishes this by fusing its core concepts with the immensely flexible Iron Software toolbox.
Developers will find it easier to select the optimal model if all license options relevant to the project are clearly described. The benefits listed above make it easier for developers to create solutions for a range of issues in a timely, coordinated, and efficient manner.
StreamJsonRpc is a cross-platform library in C# designed for facilitating remote procedure calls (RPC) using the JSON-RPC protocol. It supports various transport protocols such as TCP/IP, named pipes, and HTTP, providing a robust mechanism for asynchronous communication.
StreamJsonRpc enhances communication in distributed systems by enabling clients to call methods on distant servers as if they were local, supporting bidirectional communication, and providing mechanisms for notifications and progress reporting.
Key features of StreamJsonRpc include bidirectional communication, transport layer agnosticism, JSON-RPC message serialization and deserialization, progress reporting, error handling, extension points, performance optimization, asynchronous support, and interoperability.
StreamJsonRpc can be used with PDF generation tools by creating a service class in C# that handles PDF generation from HTML content. This setup allows remote clients to invoke PDF generation tasks over StreamJsonRpc, utilizing the capabilities of the PDF tool to convert HTML to PDF.
A PDF library in C# enables applications to create, read, and edit PDF documents. It supports converting HTML, CSS, and JavaScript into high-quality PDFs, adding headers and footers, and performing various PDF manipulations such as splitting, merging, and watermarking.
StreamJsonRpc supports asynchronous operations by leveraging .NET events to handle incoming requests and responses, which helps improve application responsiveness and scalability in distributed systems.
To set up StreamJsonRpc in a C# project, you need to create a .NET project, install the StreamJsonRpc package from NuGet, implement a JSON-RPC server, and configure a client to communicate with the server, handling method invocation over a chosen transport protocol.
A PDF library handles PDF conversion by transforming HTML, CSS, and JavaScript content into PDFs. It supports modern web standards like media queries and responsive design, and it can also convert Word, Excel, and image files to PDF.
StreamJsonRpc is transport layer agnostic and supports various transport protocols, including HTTP, Named Pipes, and TCP/IP, allowing developers to choose the most suitable transport based on application needs.
StreamJsonRpc provides comprehensive error-handling features to manage exceptions and issues that arise during remote method invocation, ensuring the resilience and reliability of distributed systems.