当前位置:网站首页>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 .
边栏推荐
- Detailed explanation of MySQL statistical function count
- 虚假新闻检测论文阅读(四):A novel self-learning semi-supervised deep learning network to detect fake news on...
- torch.nn.Embedding()详解
- Research on the implementation principle of reentrantlock in concurrent programming learning notes
- 第三周周报 ResNet+ResNext
- Spring, summer, autumn and winter with Miss Zhang (3)
- Spring, summer, autumn and winter with Miss Zhang (1)
- Yum local source production
- 【Clustrmaps】访客统计
- 个人学习网站
猜你喜欢
Centos7 silently installs Oracle
GA-RPN:引导锚点的建议区域网络
第2周学习:卷积神经网络基础
Exploration of flutter drawing skills: draw arrows together (skill development)
[image classification] how to use mmclassification to train your classification model
[semantic segmentation] Introduction to mapillary dataset
一、迁移学习与fine-tuning有什么区别?
Ffmpeg creation GIF expression pack tutorial is coming! Say thank you, brother black fly?
【Transformer】AdaViT: Adaptive Vision Transformers for Efficient Image Recognition
微信小程序源码获取(附工具的下载)
随机推荐
Is flutter being quietly abandoned? On the future of flutter
虚假新闻检测论文阅读(一):Fake News Detection using Semi-Supervised Graph Convolutional Network
Detailed explanation of atomic operation classes atomicreference and atomicstampedreference in learning notes of concurrent programming
"Full flash measurement" database acceleration solution
通过简单的脚本在Linux环境实现Mysql数据库的定时备份(Mysqldump命令备份)
【语义分割】SETR_Rethinking Semantic Segmentation from a Sequence-to-Sequence Perspective with Transformer
isAccessible()方法:使用反射技巧让你的性能提升数倍
电脑视频暂停再继续,声音突然变大
【bug】XLRDError: Excel xlsx file; not supported
Tear the ORM framework by hand (generic + annotation + reflection)
研究生新生培训第三周:ResNet+ResNeXt
一、Focal Loss理论及代码实现
ABSA1: Attentional Encoder Network for Targeted Sentiment Classification
[target detection] generalized focal loss v1
[overview] image classification network
二、深度学习数据增强方法汇总
Technology that deeply understands the principle of MMAP and makes big manufacturers love it
clion+opencv+aruco+cmake配置
Android studio login registration - source code (connect to MySQL database)
[semantic segmentation] full attention network for semantic segmentation