我是WCF的新手,我爲httpwebrequest創建了一個SSRS報告服務,並以PDF或EXCEL格式呈現報告並將其保存到驅動器上的特定位置。來自wcf服務的Httpwebrequest
我正在從web應用程序調用此按鈕單擊事件的服務。但它給在GetResponse的)錯誤(
The remote server returned an error: (403) Forbidden
另外,我有創建控制檯應用程序相同的代碼,它可以完美運行。
下面是我的代碼
public class ReportGenerator : IReportGenerator
{
public void ReportRequest()
{
try
{
string URL = "http://localhost/ReportServer2008?/ssrswcf/ssrswcftest";
string Command = "Render";
string Format = "PDF";//"EXCEL"
URL = URL + "&rs:Command=" + Command + "&rs:Format=" + Format + "&sid=5";
System.Net.HttpWebRequest Req = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(URL);
Req.UseDefaultCredentials = true;
Req.Method = "GET";
string path = @"C:\ssrswcftest\" + Convert.ToString(Guid.NewGuid()) + @".pdf";
System.Net.WebResponse objResponse = Req.GetResponse();
System.IO.FileStream fs = new System.IO.FileStream(path, System.IO.FileMode.Create);
System.IO.Stream stream = objResponse.GetResponseStream();
byte[] buf = new byte[1024];
int len = stream.Read(buf, 0, 1024);
while (len > 0)
{
fs.Write(buf, 0, len);
len = stream.Read(buf, 0, 1024);
}
stream.Close();
fs.Close();
}
catch (WebException ex)
{
//
}
catch (Exception ex)
{
//
}
}
}
下面是小提琴手細節
使用具有錯誤請求頭
GET /ReportServer2008?/ssrswcf/ssrswcftest&rs:Command=Render&rs:Format=PDF&sid=5 HTTP/1.1
Authorization: Negotiate some_long_string
Host: xyz
IIS
WCF託管
響應頭
HTTP/1.1 403 Forbidden
Cache-Control: private
Content-Length: 2925
Content-Type: text/html; charset=utf-8
Server: Microsoft-HTTPAPI/2.0
X-AspNet-Version: 2.0.50727
Date: Mon, 22 Jun 2015 15:39:29 GMT
WCF使用控制檯應用程序工作完美
請求頭
GET /ReportServer2008?/ssrswcf/ssrswcftest&rs:Command=Render&rs:Format=PDF&sid=5 HTTP/1.1
Authorization: Negotiate some_long_string
Host: xyz
響應頭
主辦HTTP/1.1 200 OK
Cache-Control: private
Content-Length: 25653
Content-Type: application/pdf
Expires: Mon, 22 Jun 2015 16:16:42 GMT
Last-Modified: Mon, 22 Jun 2015 16:17:43 GMT
Set-Cookie: RSExecutionSession%3a%2fssrswcf%2fssrswcftest=aywu4s45sefnmw45z50bn2vh; path=/
Server: Microsoft-HTTPAPI/2.0
X-AspNet-Version: 2.0.50727
FileExtension: pdf
Content-Disposition: attachment; filename="ssrswcftest.pdf"
Date: Mon, 22 Jun 2015 16:17:42 GMT
我懷疑這是同樣的請求,出去...使用小提琴來攔截btoh請求並比較它們。也許一個Windows Auth的事情。 – usr
感謝您的回覆,我會盡快回復您。 – Maddy
我不確定,但小提琴手沒有顯示任何請求正在經歷。僅供參考,我曾嘗試從控制檯應用程序託管相同的wcf服務,然後它工作正常,但來自IIS的主機wcf存在問題。 – Maddy