I don't know what a good solution is available for report reports in silvelright, except for the Silverlight report controls developed by companies such as devexpress and telerik on the 3rd side. I did not find a decent open-source solution in Google's crazy search. In comparison, select the devexpress report control.
The following content uses devexpress report to complete a report:
There are two methods
1) The report and Silverlight app are in two different windows Windows.
2) reports are embedded in the Silverlight page
Either way depends on the specific requirements.
First, add report. SVC to the Silverlight host web:
/// <Summary>
/// Ireportservice
/// </Summary>
[Servicecontract]
Public interfaceIreportservice: Devexpress. xtrareports. Service. ireportservice {
[Operationcontract]
Entid getreportsbyname (string reportname );
}
/// <Summary>
/// Reportservice
/// </Summary>
[Aspnetcompatibilityrequirements (requirementsmode = aspnetcompatibilityrequirementsmode. Allowed)]
Public classReportservice: Devexpress. xtrareports. Service. reportservice, ireportservice {
Public reportservice (){
}
Const string filepath = "~ /Reports ";
Public byte [] getreportfile (string path)
{
Return file. readallbytes (PATH );
}
Private Static string getabsulotepath (string path)
{
Return "\" + path;
}
Public entid getreportsbyname (string reportname)
{
// Xtrareport report = new xtrareport ();
String Path = httpcontext. Current. server. mappath (filepath + "//" + reportname + ". repx ");
Byte [] bytes = getreportfile (PATH );
Xtrareport report = xtrareport. fromstream (New memorystream (bytes), true );
// Report. datasource = getdata ();
Entid Doc = startbuild (report );
Return Doc;
}
}
Page in Silverlight project: XAML
<Grid X: Name = "layoutroot">
<Stackpanel orientation = "vertical">
<Button content = "button" width = "50" Height = "20" Click = "button_click"> </button>
<My: documentpreview name = "documentpreview1"/>
</Stackpanel>
</GRID>
Place a documentpreview. When a button is clicked, the report is rendered using documentpreview, mainpage. CS
Private void button_click (Object sender, routedeventargs E)
{
Reportservice. reportserviceclient client = new reportserviceclient ();
Client. getreportsbynamecompleted + = new eventhandler <getreportsbynamecompletedeventargs> (client_getreportsbynamecompleted );
Client. getreportsbynameasync ("xtrareport1 ");
}
Void client_getreportsbynamecompleted (Object sender, getreportsbynamecompletedeventargs E)
{
Reportpreviewmodel previewmodel = new reportpreviewmodel (serviceuri. absoluteuri );
Previewmodel.Processdocument(E. Result );
Documentpreview1.model = previewmodel;
// Throw new notimplementedexception ();
}
Const string relativeserviceurl = "/reportservice. SVC ";
Static URI serviceabsoluteuri;
Internal static URI serviceuri
{
Get
{
If (serviceabsoluteuri = NULL)
Serviceabsoluteuri = new uri (application. Current. Host. source, "..." + relativeserviceurl );
Return serviceabsoluteuri;
}
}
Note that servicereference. clientconfig:
<Endpoint address = "http: // localhost: 53609/reportservice. SVC % 22
Binding = "basichttpbinding" bindingconfiguration = "basichttpbinding_ireportservice"
Contract = "reportservice. ireportservice" name = "basichttpbinding_ireportservice"/>
Contract is reportservice. ireportservice
This is a simple devexpress report.
Environment: Visual Studio 2010, silverlight4 devexpress v10.1