Print a Remotely Created Document
- 3 minutes to read
This tutorial illustrates how to use the Document Preview for WPF to publish a document that is generated remotely by the WCF report service.
Create a WPF Application
To get started with this tutorial, open an existing WPF Application with a print preview, or create a new one from scratch. To learn how to add a print preview to a WPF application, refer to the Document Preview tutorial.
Prepare the Server Part
To add a server-side application to the solution, right-click the solution item in the Solution Explorer. In the invoked drop-down menu, point to Add, and then select NewProject.
In the invoked dialog, expand the Visual C# category, select Web, select ASP.NET Web Application (.NET Framework) and click OK.
The New ASP.NET Web Application dialog is invoked. Select Empty and click OK.
Next, add a report service to the server-side application. To do this, right-click the WebApplication1 item in the solution explorer. In the invoked drop-down menu, point to Add, and then select New Item.
In the invoked Add New Item dialog, expand the Visual C# category, select Reporting, select DevExpress v24.2 Report Service and click Add.
- In the same way, add a report to the server-side application.
- Design a layout for the added report. For instructions on how to create different report layouts, refer to the Create Reports documentation section.
Prepare the Client Part
- Switch to the WPF project and handle the main window’s Loaded event. In the event handler, create a RemoteDocumentSource that the Document Preview uses to obtain document data from the server.
To establish a connection to the server-side application, specify the following properties of the created RemoteDocumentSource.
- ServiceUri - specifies a report service endpoint address.
- ReportName - specifies a fully-qualified report name.
Be sure to specify the correct port in the ServiceUri property. To check which port is used by your project, select the server-side application in the Solution Explorer, and check the URL property in the Properties window. For information on how to change the port used by your web application, refer to the following topic: How to: Specify a Port for the Development Server.
- Assign the remote document source to the DocumentViewerControl.DocumentSource property of the Document Viewer Control.
- Next, call the RemoteDocumentSource.CreateDocument method to generate the document for the print preview.
The following code sample illustrates the described steps.
using DevExpress.ReportServer.Printing;
using System.Windows;
// ...
private void Window_Loaded(object sender, RoutedEventArgs e) {
RemoteDocumentSource documentSource = new RemoteDocumentSource() {
ServiceUri = "http://localhost:53206/ReportService1.svc",
ReportName = "WebApplication1.XtraReport1, WebApplication1"
};
documentPreview1.DocumentSource = documentSource;
documentSource.CreateDocument();
}
Launch the Application and View the Result
The client-side print preview is now capable of obtaining documents created on the application’s server side.
To preview the document, run the application. To print or export the previewed report, use corresponding toolbar commands.
Limitations
When the Document Preview shows remotely created documents, it does not provide the following capabilities:
- Change document page settings in the Page Setup dialog;
- Scale the document content;
- Display thumbnails;
- Use editing fields;
- Search for a specific text using the Search panel;
- Add watermarks.