レポートのパラメーターを WebRequest として渡した後、SSRS 2005 レポートを HTML 形式で要求する ASP.NET アプリケーションがあります。アプリケーションは、多数の複数選択パラメーターを含むレポートが要求された場合にのみ失敗し、行に「414: 要求 URI が長すぎます」というエラーがスローされますwebRequest.GetResponse()
。
リクエストを行うために使用されるコードは次のとおりです。
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();
サーバー側でレポートが失敗するため、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();
webRequest の requestURI にはパラメーターが格納されていませんが、GetReponse() 関数が webRequest の「address」プロパティにパラメーターを追加しているようです。これは問題でしょうか?もしそうなら、どうすれば修正できますか。