在我深入研究之前,我想概述一下我要做的事情。我们正在尝试使用Windows Auth将我们的webapp连接到2012 SSRS实例,并且未经授权使用401。
但是,如果我浏览到我尝试执行服务的URL并使用我在LogonUser方法中传递的凭据,我就可以正常使用wsdl了。所以,我认为问题出在代码端而不是服务器上。 (浏览和webapp测试都发生在我的机器上,所以我不认为这是一个域名问题或类似问题。)
好的,一些细节。
我们目前有一个旧的2008实例,它使用了一些我们想要离开的自定义身份验证。但是,我仍然认为我可以使用它作为如何连接到2012执行服务的模型(或者我认为),只需使用windows auth凭证。
我们的旧模型有一个Web服务引用,并且有一个扩展该引用的类。这个类实现了GetWebRequest和GetWebResponse,就像我认为的那样。所以我获得了对2012执行服务的Web引用并设置了一个类似的代理类,而是扩展了它。
public class ReportExecutionService2012Proxy : ReportExecution2012.ReportExecutionService
{
/// <summary>
/// Override the GetWebRequest method to attach the auth cookie.
/// </summary>
/// <param name="uri"></param>
/// <returns></returns>
protected override WebRequest GetWebRequest(Uri uri)
{
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri);
request.CookieContainer = new CookieContainer(); ;
// if the client already has an auth cookie
// place it in the request's cookie container
if (AuthCookie != null)
request.CookieContainer.Add(AuthCookie);
request.Timeout = -1;
request.Headers.Add("Accept-Language", HttpContext.Current.Request.Headers["Accept-Language"]);
return request;
}
/// <summary>
/// Override GetWebResponse to check for the auth cookie.
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2201:DoNotRaiseReservedExceptionTypes")]
protected override WebResponse GetWebResponse(WebRequest request)
{
WebResponse response = base.GetWebResponse(request);
string cookieName = response.Headers["RSAuthenticationHeader"];
// If the response contains an auth header, store the cookie
if (cookieName != null)
{
Utilities.CustomAuthCookieName = cookieName;
HttpWebResponse webResponse = (HttpWebResponse)response;
Cookie authCookie = webResponse.Cookies[cookieName];
// If the auth cookie is null, throw an exception
if (authCookie == null)
{
throw new Exception(
"Authorization ticket not received by LogonUser");
}
// otherwise save it for this request
AuthCookie = authCookie;
// and send it to the client
// TCK 7/25/2011: This was causing MKO to switch auth keys and force logout. I'm not sure if I'm just
// hitting the most obvious problem and the root problem is deeper, but this does appear to fix it.
//Utilities.RelayCookieToClient(authCookie);
}
if ((response is HttpWebResponse) && ((HttpWebResponse)response).StatusCode == HttpStatusCode.InternalServerError)
{
var stream = new StreamReader(response.GetResponseStream());
var content = stream.ReadToEnd();
}
return response;
}
/// <summary>
/// Private property used to store the Auth Cookie.
/// </summary>
private Cookie AuthCookie
{
get
{
if (m_Authcookie == null)
m_Authcookie = Utilities.TranslateCookie(Utilities.AuthSource.GetCookie(Utilities.CustomAuthCookieName));
return m_Authcookie;
}
set
{
m_Authcookie = value;
}
}
private Cookie m_Authcookie = null;
}
当我们准备好加载报告时,我们会实例化此代理(如果它还没有)并尝试登录该服务。在这一点上,我们得到了401。
private reporting.proxy.ReportExecutionService2012Proxy _rsExec2012Proxy = null;
public virtual reporting.proxy.ReportExecutionService2012Proxy RsExec2012Proxy
{
get
{
if (_rsExec2012Proxy == null)
{
_rsExec2012Proxy = new reporting.proxy.ReportExecutionService2012Proxy();
_rsExec2012Proxy.Url = reporting.ReportConfiguration.ReportExecutionSevice2012Url;
ReportServerCredentials creds =
new ReportServerCredentials(reporting.ReportConfiguration.ReportService2012Username,
reporting.ReportConfiguration.ReportService2012Password,
reporting.ReportConfiguration.ReportService2012Domain);
_rsExec2012Proxy.Credentials = creds.NetworkCredentials;
_rsExec2012Proxy.LogonUser(
reporting.ReportConfiguration.ReportService2012Username,
reporting.ReportConfiguration.ReportService2012Password,
reporting.ReportConfiguration.ReportService2012Domain);
}
return _rsExec2012Proxy;
}
}
因此,我们从配置中获取服务的URL和凭据,并尝试进入服务,但没有骰子。
我一直在阅读这篇文章,并且不能很好地理解这个问题,以便更进一步。任何想法都赞赏。
答案 0 :(得分:1)
因此,首先,当您拥有自定义安全扩展(即不仅仅使用vanilla Windows /基本身份验证)时,仅使用LogonUser。并且因为您使用的是自定义安全性,所以只能调用它反对SSL连接。
那么您的2012实例有安全扩展吗?如果没有,只需实例化服务,在其上设置Credentials属性,然后针对它发出请求。
这是an MSDN sample of connecting against a 2005 SSRS Execution Service,但截至2012年,它几乎保持不变。