您的位置:首页 > 数据库

Sql Server Reporing Service / Windows Azure SQL Reporting应用程序开发

2013-04-29 11:23 489 查看
一.SqlserverReporingService应用程序集成

Tocompilethefollowingcodeexample,youmustreferencetheReportingServicesWSDLandimportcertainnamespaces.Formoreinformation,seeCompilingandRunningCodeExamples.ThefollowingcodeexamplerendersareportinMHTMLandsavesitasan.mhtfiletodisk.

C#

复制

usingSystem;
usingSystem.IO;
usingSystem.Web.Services.Protocols;
usingmyNamespace.MyReferenceName;

classSample
{
staticvoidMain(string[]args)
{
ReportExecutionServicers=newReportExecutionService();
rs.Credentials=System.Net.CredentialCache.DefaultCredentials;
rs.Url="http://myserver/reportserver/ReportExecution2005.asmx";

//Renderarguments
byte[]result=null;
stringreportPath="/AdventureWorksSampleReports/EmployeeSalesSummary";
stringformat="MHTML";
stringhistoryID=null;
stringdevInfo=@"<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>";

//Preparereportparameter.
ParameterValue[]parameters=newParameterValue[3];
parameters[0]=newParameterValue();
parameters[0].Name="EmpID";
parameters[0].Value="288";
parameters[1]=newParameterValue();
parameters[1].Name="ReportMonth";
parameters[1].Value="6";//June
parameters[2]=newParameterValue();
parameters[2].Name="ReportYear";
parameters[2].Value="2004";

DataSourceCredentials[]credentials=null;
stringshowHideToggle=null;
stringencoding;
stringmimeType;
stringextension;
Warning[]warnings=null;
ParameterValue[]reportHistoryParameters=null;
string[]streamIDs=null;

ExecutionInfoexecInfo=newExecutionInfo();
ExecutionHeaderexecHeader=newExecutionHeader();

rs.ExecutionHeaderValue=execHeader;

execInfo=rs.LoadReport(reportPath,historyID);

rs.SetExecutionParameters(parameters,"en-us");
StringSessionId=rs.ExecutionHeaderValue.ExecutionID;

Console.WriteLine("SessionID:{0}",rs.ExecutionHeaderValue.ExecutionID);

try
{
result=rs.Render(format,devInfo,outextension,outencoding,outmimeType,outwarnings,outstreamIDs);

execInfo=rs.GetExecutionInfo();

Console.WriteLine("Executiondateandtime:{0}",execInfo.ExecutionDateTime);

}
catch(SoapExceptione)
{
Console.WriteLine(e.Detail.OuterXml);
}
//WritethecontentsofthereporttoanMHTMLfile.
try
{
FileStreamstream=File.Create("report.mht",result.Length);
Console.WriteLine("Filecreated.");
stream.Write(result,0,result.Length);
Console.WriteLine("Resultwrittentothefile.");
stream.Close();
}
catch(Exceptione)
{
Console.WriteLine(e.Message);
}

}
}

摘自:http://msdn.microsoft.com/zh-cn/library/reportexecution2005.reportexecutionservice.render.aspx


二.WindowsAzureSQLReporting应用程序集成

DeviceinformationsettingsinSSRSareusedtopassparameterstoarenderingextension.Formoreinformationregardingdeviceinformationsettingsinreportingservices,seePassingDeviceInformationSettingstoRenderingExtensions.

ForSQLReporting,noneoftheoptionsspecifiedintheabovearticlearefeasible.Weseealotofscenarioswherewewouldwanttomodifythesesettings,andrender/exportthereportintheformatthatwearelookingfor.

ForSQLReportingreports,wecanexploretheSOAPAPIsinmodifyingthesedeviceinformationsettingsattheruntime.IfwehaveintegratedSQLReportingwithinourapplications,thisapproachisreallyeasy,byjustcreatingaseparatefunction.

Herearesomestepstoachievethis:

GeneratetheproxyclassforReportExecution2005.asmx.

Inthebrowser,gotothepathforyourendpoint.Forexample:https://<INSTANCE_NAME>.report.int.mscds.com/ReportServer/ReportExecution2005.asmx

Ifpromptedforcredentials,typeyourSQLReportingusernameandpasswordandclickSignIn.AWSDLfilewillbedisplayedinthebrowser.

OpentheVisualStudioCommandPromptandrunthewsdl.execommandtogeneratetheproxyclass.Forexample:wsdl/language:CS/n:"ReportExecution2005"https://<INSTANCE_NAME>.report.int.mscds.com/ReportServer/ReportExecution2005.asmx

Nowyouhavethefilenamed:ReportExecutionService.cs.AddthefiletoyourWindowsAzureProject.Youcanuseafunctionsimilartotheoneprovidedbelow:

publicvoidRender_Export()

{

ReportExecutionServicers=newReportExecutionService();

rs.Url=String.Format("https://{0}:443/ReportServer/reportExecution2005.asmx",ConfigurationManager.AppSettings["SERVER_NAME"]);

rs.CookieContainer=newCookieContainer();

rs.LogonUser(ConfigurationManager.AppSettings["USERNAME"],ConfigurationManager.AppSettings["PASSWORD"],ConfigurationManager.AppSettings["SERVER_NAME"]);


byte[]result=null;

stringreportPath="/SSRSReport/Report5";

stringformat="CSV";

stringhistoryID=null;


//Settingthedeviceinfoparameters

stringdevInfo=@"<DeviceInfo><FieldDelimiter>;</FieldDelimiter></DeviceInfo>";


stringencoding;

stringmimeType;

stringextension;

Warning[]warnings=null;

string[]streamIDs=null;


ExecutionInfoexecInfo=newExecutionInfo();

ExecutionHeaderexecHeader=newExecutionHeader();


rs.ExecutionHeaderValue=execHeader;

execInfo=rs.LoadReport(reportPath,historyID);

StringSessionId=rs.ExecutionHeaderValue.ExecutionID;


//codesnippettosettheDataSourcecredentials.

if(execInfo.CredentialsRequired)

{

List<DataSourceCredentials>credentials=newList<DataSourceCredentials>();

foreach(DataSourcePromptdspinexecInfo.DataSourcePrompts)

{

DataSourceCredentialscred=newDataSourceCredentials();

cred.DataSourceName=dsp.Name;

cred.UserName=ConfigurationManager.AppSettings["USERNAME"];

cred.Password=ConfigurationManager.AppSettings["PASSWORD"];

credentials.Add(cred);

}


Console.WriteLine("Settingdatasourcecredentials...");

execInfo=rs.SetExecutionCredentials(credentials.ToArray());

}


//Codesnippettorenderthefiletoaspecifiedformat.

try

{

result=rs.Render(format,devInfo,outextension,outencoding,outmimeType,outwarnings,outstreamIDs);

execInfo=rs.GetExecutionInfo();

}

catch(Exceptionex)

{

throwex;

}


//CodesnippettowritethefiletoaspecificlocationusingFileStreamobject

try

{

FileStreamstream=File.Create(@"D:\report.csv",result.Length);

Console.WriteLine("Filecreated.");

stream.Write(result,0,result.Length);

Console.WriteLine("Resultwrittentothefile.");

stream.Close();

}

catch(Exceptionex)

{

Console.WriteLine(ex.Message);

}

}


YoucanuseaconfigfiletostoretheUsername,PasswordandSQLReportingservername.Theconfigfilewillhaveinformationasspecifiedbelow:

<appSettings>

<addkey="SERVER_NAME"value="SQLReportingServer.reporting.windows.net"/>

<addkey="USERNAME"value="UserName"/>

<addkey="PASSWORD"value="Password"/>

</appSettings>


ModifythevaluesasperyourSQLReportingserverdetails.

YoumightneedtoextendthedefaultReportingServicesproxyclasstoenablecookiemanagement,becauseSQLReportingusesformsauthentication.

FormoreinformationaboutunsupportedAPIsinSQLReporting,seehttp://msdn.microsoft.com/en-us/library/windowsazure/gg430132#UnsupportedAPIs

摘自:http://blogs.msdn.com/b/chaitanya_medikonduri/archive/2012/06/19/windows-azure-sql-reporting-using-soap-apis.aspx
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: