带报告服务的C#代理

时间:2016-03-15 15:10:38

标签: c# windows-authentication

我正在尝试整理一个简单的C#代理代码来调用ssrs报告。 这是我的C#代码:

[HttpGet]
    [Route("reportProxy")]
    public IHttpActionResult get(string report)
    {
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://localhost/Reportserver_SQL2014?/....");
        WebProxy myproxy = new WebProxy();
        myproxy.Credentials = new NetworkCredential(username, password);
        request.Proxy = myproxy;
        request.Method = "GET";
        HttpWebResponse response = (HttpWebResponse)request.GetResponse();
        return Ok(response);

    }

我正在调用我的代理方法:

http://localhost/reportProxy?report=1234

我收到401错误,看起来像这样:

  

{“Message”:“发生错误。”,“ExceptionMessage”:“远程服务器返回错误:(401)Unauthorized。”,“ExceptionType”:“System.Net.WebException”,“StackTrace” :“在System.Net.HttpWebRequest.GetResponse()\ r \ n,在UtilityController.cs中的PrismWeb.API.Controller.UtilityController.get(String report):line 248 \ r \ n在lambda_method(Closure,Object,Object [ ])\ r \ n在System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor。<> c__DisplayClass10.b__9(Object instance,Object [] methodParameters)\ r \ n在System.Web.Http.Controllers.ReflectedHttpActionDescriptor。 ActionExecutor.Execute(Object instance,Object [] arguments)\ r \ n在System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext,IDictionary`2 arguments,CancellationToken cancellationToken)\ r \ n ---堆栈结束从抛出异常的先前位置追踪--- \ r \ n在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)\ r \ n \ n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)\ r \ n在System.Web.Http.Controllers.ApiControllerActionInvoker.d__0.MoveNext()\ r \ n ---从前一个位置的堆栈跟踪结束抛出异常的地方--- \ r \ n在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)\ r \ n在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)\ r \ n在System。 Web.Http.Controllers.ActionFilterResult.d__2.MoveNext()\ r \ n ---从抛出异常的上一个位置开始的堆栈跟踪结束--- \ r \ n在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务)任务)\ r \ n在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)\ r \ n在System.Web.Http.Controllers.AuthenticationFilterResult.d__0.MoveNext()\ r \ n ---堆栈结束从抛出异常的先前位置追踪--- \ r \ n在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSucce ss(任务任务)\ r \ n在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)\ r \ n在System.Web.Http.Dispatcher.HttpControllerDispatcher.d__1.MoveNext()“}

我可以使用Windows身份验证吗?

感谢您的帮助。

0 个答案:

没有答案