BId*_*ude 10 c# iis httpwebrequest reporting-services getresponse
我们有一个ASP.NET应用程序,它在将报告的参数作为WebRequest传递后,以HTML格式请求SSRS 2005报告.只有在请求具有大量多选参数的报表时,应用程序才会失败,从而在该webRequest.GetResponse()行处抛出"414:Request URI too long"错误.
用于发出请求的代码是:
HttpWebRequest webRequest = null;
HttpWebResponse webResponse = null;
string webRequestURL = _ReportManager.GetRSUrl(reportID); //this passes the report link on the SSRS server
//make the request
Byte[] bytes = Encoding.UTF8.GetBytes("xml_doc=" + HttpUtility.UrlEncode(webRequestURL));
webRequest = (HttpWebRequest)WebRequest.Create(webRequestURL);
webRequest.Method = "POST";
webRequest.ContentLength = bytes.Length;
webRequest.Timeout = Configuration.WebRequestTimeOut;
RSExecution2005.ReportExecutionService rsE = new RSExecution2005.ReportExecutionService();
rsE.Url = Configuration.ReportExecutionServiceUrl2005;
rsE.Credentials = System.Net.CredentialCache.DefaultCredentials;
webRequest.Credentials = rsE.Credentials;
Stream reqStream = null;
reqStream = webRequest.GetRequestStream();
reqStream.Write(bytes, 0, bytes.Length);
reqStream.Close();
webResponse = (HttpWebResponse)webRequest.GetResponse();
Run Code Online (Sandbox Code Playgroud)
由于报告在服务器端失败,我已经查看了IIS和ReportServer属性,以字节方式增加maxUrl,maxRequestLength,MaxQueryString等(根据本文),但应用程序仍然会抛出错误.我已经在web.config文件中尝试过这个并直接在IIS管理器上.
2005年的报告服务器版本,它托管在运行IIS 7的Windows Server 2008上.
在David Lively的建议中,我尝试通过将参数放在正文中来请求URI.这适用于较小的请求,但仍然无法用于大型多选参数.修订后的代码如下:
HttpWebRequest webRequest = null;
HttpWebResponse webResponse = null;
string webRequestURL = _ReportManager.GetRSUrl(reportID); //this passes the report link on the SSRS server
string postData = string.Empty;
string URIrequest = string.Empty;
URIrequest = webRequestURL.Substring(0, webRequestURL.IndexOf("&"));
int requestLen = webRequestURL.Length;
int postDataStart = webRequestURL.IndexOf("&") + 1;
postData = webRequestURL.Substring(postDataStart, (requestLen - postDataStart));
Byte[] bytes1 = Encoding.UTF8.GetBytes(postData);
webRequest = (HttpWebRequest)WebRequest.Create(URIrequest);
webRequest.Method = "POST";
webRequest.ContentType = "application/x-www-form-urlencoded";
webRequest.ContentLength = bytes1.Length;
webRequest.Timeout = Configuration.WebRequestTimeOut;
RSExecution2005.ReportExecutionService rsE = new RSExecution2005.ReportExecutionService();
rsE.Url = Configuration.ReportExecutionServiceUrl2005;
rsE.Credentials = System.Net.CredentialCache.DefaultCredentials;
webRequest.Credentials = rsE.Credentials;
Stream reqStream = webRequest.GetRequestStream();
reqStream.Write(bytes1, 0, bytes1.Length);
reqStream.Close();
webResponse = (HttpWebResponse)webRequest.GetResponse();
Run Code Online (Sandbox Code Playgroud)
即使webRequest的requestURI不存储参数,似乎GetReponse()函数也将参数添加到webRequest的'address'属性中.这可能是问题吗?如果是的话,怎么解决呢.
您是否可以使用POST变量而不是GET?这样,我没有任何限制,因为所有数据都将以数据包而不是HTTP标头发送.
实际上,您可能正在使用代码中的POST.您是否可以查看服务器日志以验证导致此失败的URI?如果您要发送POST数据,请求uri不应成为问题,除非它与您正在发布的数据无关.
| 归档时间: |
|
| 查看次数: |
11491 次 |
| 最近记录: |