当前位置:网站首页>ReportingService WebService form authentication
ReportingService WebService form authentication
2022-07-29 06:05:00 【Denny Hui】
The premise of this verification is that the authentication of your report server has been changed to Form Verified no longer Windows Authenticated . Then you call ReportingService Because the default is windows verification , At this time, we need to make some adjustments .
stay MSDN As mentioned above :
Reporting Services Web service Provide custom authentication , In order to Report Manager And the report server can perform form authentication .
Reporting Services Web service Of LogonUser Method is used to submit credentials to the report server , To authenticate .Web service Use HTTP The header will authenticate the ticket ( be called “Cookie”) From the server to the client , In response to an authenticated login request .
The authentication process is as follows :
- Client application calls Web service Method LogonUser Authenticate users .
- Web service Call security extension ( To be specific , It refers to the realization IAuthenticationExtension Class ) Of LogonUser Method .
- LogonUser The implementation of verifies the user name and password stored in the user or security organization .
- After successful authentication ,Web service Will be created Cookie And manage it for the session .
- Web service adopt HTTP The header returns the authentication ticket to the calling application .
Web service After successfully authenticating the user through security extension , Will generate a Cookie, For subsequent requests . Because the report server has no security mechanism , So it's time to Cookie It will not always be saved in the custom security mechanism .Cookie from Web service Method LogonUser return , And used for subsequent Web service Method calls and URL visit .
Specific use :
take Web Service For custom security authentication , Can be Web service API For form authentication , It's like going to Windows Authentication Used for form authentication . however , Must call Web service In code LogonUser, And pass the credentials of the current user . Besides ,Web service The client will not have Internet Explorer Or others Web Automatic provided by browser Cookie management function . It has to be expanded ReportingService Proxy classes to contain Cookie management . So , You can override Web service Class GetWebRequest and GetWebResponse Method .
Create a project , Then the reference ReportService2005.asmx Of web service .
protected void Page_Load(object sender, EventArgs e)
{
RenderReport report = new RenderReport();
byte [] result = report.RenderReportToPDF();
//To display the PDF in web browser, set the right content type.
Response.ContentType = “Application/pdf”;
//Write the byte array to the default output stream.
Response.OutputStream.Write(result, 0, result.Length);
//Flush the contents to be displayed in the browser.
Response.Flush();
}
//Clash to take care of report rendering
public class RenderReport : ReportingService2005
{
//Change to point to your report.
private string ReportPath = “/Test”;
private string m_authCookieName;
private Cookie m_authCookie;
public RenderReport()
{
// Set the server URL. You can pull this from a config file or what ever way you want to make it dynamic.
base.Url = http://kaneco1/reportserver2008/reportservice2005.asmx;
// Calling the LogonUser method defined in the ReportService2005.asmx end point.
// The LogonUser method authenticates the specified user to the Report Server Web Service when custom authentication has been configured.
// This is to authenticate against the FBA code and then store the cookie for future reference.
try
{
base.LogonUser(“FBA username”, “password”, null);
}
catch (Exception
)
{
}
}
/// <summary>
/// Overriding the method defined in the base class.
/// </summary>
/// <param name=”uri”></param>
/// <returns></returns>
protected override WebRequest GetWebRequest(Uri uri)
{
HttpWebRequest request;
request = (HttpWebRequest)HttpWebRequest .Create(uri);
request.Credentials = base .Credentials;
request.CookieContainer = new CookieContainer ();
if (m_authCookie != null
)
{
request.CookieContainer.Add(m_authCookie);
}
return request;
}
/// <summary>
/// Overriding the method defined in the base class.
/// </summary>
/// <param name=”request”></param>
/// <returns></returns>
protected override WebResponse GetWebResponse(WebRequest request)
{
WebResponse response = base .GetWebResponse(request);
string cookieName = response.Headers[“RSAuthenticationHeader”];
if (cookieName != null)
{
m_authCookieName = cookieName;
HttpWebResponse webResponse = (HttpWebResponse )response;
Cookie authCookie = webResponse.Cookies[cookieName];
// save it for future reference and use.
m_authCookie = authCookie;
}
return response;
}
/// <summary>
///Simplified implementation from http://msdn.microsoft.com/en-us/library/reportexecution2005.reportexecutionservice.render.aspx
/// Additionaly it is autheticating against the custom security extension. In our case it is FBA.
/// </summary>
/// <returns>Byte array containing the rendered report in PDF format </returns>
public byte [] RenderReportToPDF()
{
//Create a proxy object for ReportExecution2005.asmx referenced in the project.
//You can pull this from a config file or what ever way you want to make it dynamic.
ReportExecutionService rs = new ReportExecutionService ();
rs.Url = “http://kaneco1/ReportServer2008/ReportExecution2005.asmx”;
//Simplified code from http://msdn.microsoft.com/en-us/library/reportexecution2005.reportexecutionservice.render.aspx
byte[] result = null;
string reportPath = “/SimpleSelect” ;
string format = “PDF”
string historyID = null;
string devInfo = “”;
string encoding;
string mimeType;
string extension;
//Since warning is definied in both ReportService2005 and ReportExecution2005 endpoints,
//qualifying it with the appropriate namespace.
WebServiceFBARenderMethod.RE2K5.Warning[] warnings = null;
string[] streamIDs = null;
//Attaching the cookie received from the LogonUser method in the constructor.
//Only when autheticated, it will proceed further with ReportExecution2005.asmx end point calls.
if (null != m_authCookie)
{
//Store the cookie in the cookie container within ReportExecutionService object.
//So any subsequent call will make use of this authenticated cookie and will be succeeding.
rs.CookieContainer = new CookieContainer();
rs.CookieContainer.Add(m_authCookie);
ExecutionInfo execInfo = new ExecutionInfo();
ExecutionHeader execHeader = new ExecutionHeader();
rs.ExecutionHeaderValue = execHeader;
execInfo = rs.LoadReport(reportPath, historyID);
try
{
result = rs.Render(format, devInfo, out extension, out encoding, out mimeType, out warnings, out streamIDs);
}
catch (SoapException e)
{
}
}
else
{
//Logic to recall the LogonUser code with proper username / password.
}
//Byte array containing the rendered report in PDF.
return result;
For more articles, please scan the code and follow the official account , If you have problems, you can also raise them on the official account .
边栏推荐
- 第一周任务 深度学习和pytorch基础
- mysql在查询字符串类型的时候带单引号和不带的区别和原因
- Flink connector Oracle CDC synchronizes data to MySQL in real time (oracle19c)
- Flutter正在被悄悄放弃?浅析Flutter的未来
- DataX installation
- tensorboard使用
- [clustmaps] visitor statistics
- [DL] introduction and understanding of tensor
- Tear the ORM framework by hand (generic + annotation + reflection)
- "Full flash measurement" database acceleration solution
猜你喜欢
ASM piling: after learning ASM tree API, you don't have to be afraid of hook anymore
mysql 的show profiles 使用。
【Transformer】TransMix: Attend to Mix for Vision Transformers
【Attention】Visual Attention Network
Are you sure you know the interaction problem of activity?
研究生新生培训第三周:ResNet+ResNeXt
Exploration of flutter drawing skills: draw arrows together (skill development)
迁移学习—— Transfer Feature Learning with Joint Distribution Adaptation
迁移学习——Transitive Transfer Learning
nacos外置数据库的配置与使用
随机推荐
【Attention】Visual Attention Network
[target detection] generalized focal loss v1
ROS教程(Xavier)
How to obtain openid of wechat applet in uni app project
[clustmaps] visitor statistics
二、深度学习数据增强方法汇总
Nailing alarm script
研究生新生培训第三周:ResNet+ResNeXt
通过简单的脚本在Linux环境实现Mysql数据库的定时备份(Mysqldump命令备份)
C connect to SharePoint online webservice
一、迁移学习与fine-tuning有什么区别?
【Transformer】AdaViT: Adaptive Tokens for Efficient Vision Transformer
[semantic segmentation] setr_ Rethinking Semantic Segmentation from a Sequence-to-Sequence Perspective with Transformer
Flink connector Oracle CDC synchronizes data to MySQL in real time (oracle12c)
【目标检测】Generalized Focal Loss V1
[target detection] 6. SSD
关于Flow的原理解析
虚假新闻检测论文阅读(四):A novel self-learning semi-supervised deep learning network to detect fake news on...
【Transformer】SOFT: Softmax-free Transformer with Linear Complexity
Show profiles of MySQL is used.