从SQL报告服务器下载的XML文件 [英] downloading XML file from sql reporting server

查看:135
本文介绍了从SQL报告服务器下载的XML文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从下载SQL Azure的报告服务器一个xml文件需要身份验证来获取文件。我想下面的方法2:

方法1

在这个方法我试过下面的C#控制台应用程序并将其下载从服务器上的文件。它工作正常!

 无效DownloadFile(字符串的uname,字符串密码)
{
        ServerReport报告=新ServerReport();
        report.ReportServerUrl =新的System.Uri(https://xxxxx.reporting.windows.net/ReportServer,System.UriKind.Absolute);
        report.ReportPath =/Demo2.rdl;
        report.ReportServerCredentials.SetFormsCredentials(NULL,UNAME,密码,xxxxx.reporting.windows.net);
        字节[]数据= report.Render(XML);
        的FileStream FS =新的FileStream(@C:\\的Output.xml,FileMode.Create);
        fs.Write(数据,0,data.Length);
        fs.Close();
}

方法2

现在我想从一个Windows Phone应用程序下载同一个文件。现在既然ServerReport是不是在Windows Phone的present我在Web客户端依靠下载的文件。所以我要把低于code和它似乎并没有工作:

 无效DownloadFile(字符串的uname,字符串密码)
{
    Web客户端Web客户端=新的WebClient();
    webClient.Credentials =新的NetworkCredential(UNAME,密码,xxxxx.reporting.windows.net);
    webClient.DownloadFile(\"https://xxxxx.reporting.windows.net/ReportServer?%2fDemo2.rdl&rs:Command=Render&rs:Format=XML\", @C:\\的Output.xml);
}

下面是方法2的输出:看起来是重新定向到登录页面

 <!DOCTYPE HTML PUBLIC -  // W3C // DTD HTML 4.0过渡// ENGT&;
    < HTML LANG =EN-US>
       <头ID =头像1>< META HTTP-EQUIV =Content-Type的CONTENT =text / html的;字符集= ISO-8859-1/><链接rel =stylesheet属性类型= 文/ CSS的href =公共/ Logon.css/><标题>
        Windows Azure的SQL报告
    < /标题>< /头>
       <身体GT;
          <表格名称=登录方法=后 action=\"logon.aspx?ReturnUrl=%2fReportServer%3f%252fDemo2.rdl%26rs%3aCommand%3dRender%26rs%3aFormat%3dXML&%2fDemo2.rdl&rs%3aCommand=Render&rs%3aFormat=XML\" ID =登录>
    <输入类型=隐藏的名字=__ VIEWSTATEID =__ VIEWSTATEVALUE =/ XXXX/>    <输入类型=隐藏的名字=__ EVENTVALIDATIONID =__ EVENTVALIDATIONVALUE =/ YYYY/>            < H1 ID =标题><跨度ID =LblTitleContent>的Windows Azure< / SPAN>< / H1>
            <小时/>
            < D​​IV CLASS =ClsIntro>
                &所述;跨度的id =LblIntro>&下; /跨度>
            < / DIV>
            < D​​IV CLASS =ClsInput>
                < D​​IV>
                    <标签=TxtUserID =LblUser>用户名< /标签>
                < / DIV>
                < D​​IV>
                    <输入名称=TxtUser类型=文本ID =TxtUser的tabindex =1/>
                < / DIV>
            < / DIV>
            < D​​IV CLASS =ClsInput>
                < D​​IV>
                    <标签=TxtPwdID =LblPwd>密码和LT; /标签>
                < / DIV>
                < D​​IV>
                    <输入名称=TxtPwdTYPE =密码ID =TxtPwd的tabindex =2/>
                < / DIV>
            < / DIV>
            < D​​IV CLASS =ClsSignIn>
                <输入类型=提交名称=BtnLogonVALUE =登录ID =BtnLogon的tabindex =4/><输入类型=形象NAME =BtnLogonArrowID =BtnLogonArrow的tabindex =5SRC =公共/ WhiteRightArrow.pngALT =登录ALIGN =基线BORDER =0/>
            < / DIV>
            < D​​IV CLASS =ClsErrMsg>
                &所述;跨度的id =lblMessage>&下; /跨度>
            < / DIV>
            <小时/>
          < /表及GT;
       < /身体GT;
    < / HTML>

有什么能与做法2的问题,我们错过任何东西吗?

更新

我很新的这Azure和Web服务。我可能会问一些愚蠢的问题。这里是我尝试:


  • 我试图在我的Windows Phone 7项目增加一个服务引用,以蔚蓝的SQL报告服务器。有一件事我注意到的是,因为它是在Windows Phone 7的应用程序禁用我不能添加的贡献莫过于为Web引用。

  • 添加serive到我的应用我得到一组类之后。其中之一是ReportExecutionServiceSoapClient;

  • ReportExecutionService不可用。

  • 我如何使用ReportExecutionServiceSoapClient API来获取,我可以使用Web客户端cookie的不太清楚。

  • 在如何使用这些API的示例应用程序将是巨大的。我试图寻找过互联网,但不能得到更多的信息。

  • 下面是我试过,但cookie计数为null。

      ReportExecutionServiceSoapClient客户端=新ReportExecutionServiceSoapClient();
    无效MainPage_Loaded(对象发件人,RoutedEventArgs E)
    {
        client.ClientCredentials.UserName.UserName =XXXX;
        client.ClientCredentials.UserName.Password =XXXX;
        client.CookieContainer =新的CookieContainer();
        client.LogonUserCompleted + =新的EventHandler< System.ComponentModel.AsyncCompletedEventArgs>(client_LogonUserCompleted);
        client.LogonUserAsync(XXXX,XXXX,xxxx.reporting.windows.net);
    }无效client_LogonUserCompleted(对象发件人,System.ComponentModel.AsyncCompletedEventArgs E)
    {
        诠释计数= client.CookieContainer.Count; // NULL cookie计数!
    }


下面是ClientConfig文件。我已经加入enableHttpCookieContainer =真。

 <结构>
        < system.serviceModel>
            <&绑定GT;
                <&basicHttpBinding的GT;
                    <绑定名称=ReportExecutionServiceSoapMAXBUFFERSIZE =2147483647
                        enableHttpCookieContainer =真
                             maxReceivedMessageSize =2147483647>
                        <安全模式=运输/>
                    < /&结合GT;
                < / basicHttpBinding的>
            < /绑定>
            <客户端>
                <端点地址=htt​​ps://xxxx.reporting.windows.net:443/ReportServer/ReportExecution2005.asmx
                    绑定=basicHttpBinding的bindingConfiguration =ReportExecutionServiceSoap
                    合同=SqlReportingService.ReportExecutionServiceSoap
                    NAME =ReportExecutionServiceSoap/>
            < /客户>
        < /system.serviceModel>
    < /结构>


  • 请让我知道什么是失踪。

解决
- 最后,我能够从Azure中的Sql下载xml文件报告服务器。
- 下面是溶液。
- 首先添加一个服务引用到SQL报告服务器。
- 然后做一个ReportExecutionServiceSoapClient :: LogonUserAsync。
- 使用所获得的Cookie与Web客户端的进一步要求

 公共类WebClientExtended:Web客户端
            {
                私人的CookieContainer myContainer中;
                私人HttpWebRequest的myRequest;
                [SecuritySafeCritical]
                公共WebClientExtended()
                {
                }                [SecuritySafeCritical]
                公共WebClientExtended(的CookieContainer containter)
                {
                    myContainer中= containter;
                }                公众的CookieContainer饼干
                {
                    {返回myContainer中; }
                    集合{myContainer中=值; }
                }                保护覆盖的WebRequest GetWebRequest(URI地址)
                {
                    myRequest =(HttpWebRequest的)base.GetWebRequest(地址);
                    myRequest.Method =GET;
                    myRequest.CookieContainer =饼干;
                    返回myRequest;
                }                保护覆盖WebResponse类GetWebResponse(WebRequest的要求,IAsyncResult的结果)
                {
                    返回myRequest.EndGetResponse(结果);
                }
            }            ReportExecutionServiceSoapClient RS =新ReportExecutionServiceSoapClient();
            字符串服务器名=XXXX.reporting.windows.net;
            字符串的uname =XXXX;
            字符串密码=XXXX;            公共无效LoadReport()
            {
                rs.ClientCredentials.UserName.UserName =的uname;
                rs.ClientCredentials.UserName.Password =密码;
                rs.CookieContainer =新的CookieContainer();
                rs.LogonUserCompleted + =新的EventHandler< System.ComponentModel.AsyncCompletedEventArgs>(rs_LogonUserCompleted);
                rs.LogonUserAsync(UNAME,密码,服务器名);            }            无效rs_LogonUserCompleted(对象发件人,System.ComponentModel.AsyncCompletedEventArgs E)
            {
                WebClientExtended Web客户端=新WebClientExtended(rs.CookieContainer);
                webClient.Credentials =新的NetworkCredential(UNAME,密码,服务器名);
                webClient.DownloadStringCompleted + =新DownloadStringCompletedEventHandler(webClient_DownloadStringCompleted);
                webClient.DownloadStringAsync(新的URI(的String.Format(https://开头{0} /ReportServer?%2fDemo2.rdl&rs:Command=Render&rs:Format=XML,服务器名)));
            }            无效webClient_DownloadStringCompleted(对象发件人,DownloadStringCompletedEventArgs E)
            {
                 MessageBox.Show(e.Result);
            }


解决方案

ServerReport 类将调用的LogonUser 在方法 ReportExecutionService 来获得,这将在所有其他请求中使用(如渲染XML)一个窗体身份验证cookie。

在你的WP7应用程序中使用的Web客户端证书不包括这一点。你有两个选择:


  • 尝试通过调用LogonUser的得到一个cookie,并在你的Web客户端使用它

  • 请不要使用Web客户端,但渲染通过ReportExecutionService
  • 的报告

看看在的Windows Azure SQL报告:使用SOAP API的博客文章开始使用在SQL Azure中此服务。

I am trying to download a xml file from Azure SQL reporting server which requires authentication to get the file. I am trying below 2 approaches:

Approach 1

In this approach i tried below c# console application and it downloads the file from server. It works fine!

void DownloadFile(string uname, string password)
{
        ServerReport report = new ServerReport();
        report.ReportServerUrl = new System.Uri("https://xxxxx.reporting.windows.net/ReportServer", System.UriKind.Absolute);
        report.ReportPath = "/Demo2.rdl";
        report.ReportServerCredentials.SetFormsCredentials(null, uname, password, "xxxxx.reporting.windows.net");
        byte[] data = report.Render("XML");
        FileStream fs = new FileStream(@"c:\output.xml", FileMode.Create);
        fs.Write(data, 0, data.Length);
        fs.Close();
}

Approach 2

Now i want to download the same file from a windows phone application. Now since ServerReport is not present in windows phone i am relying in WebClient to download the file. So i am trying below code and it doesn't seem to work:

void DownloadFile(string uname, string password)
{
    WebClient webClient = new WebClient();
    webClient.Credentials = new NetworkCredential(uname, password, "xxxxx.reporting.windows.net");    
    webClient.DownloadFile("https://xxxxx.reporting.windows.net/ReportServer?%2fDemo2.rdl&rs:Command=Render&rs:Format=XML", @"c:\output.xml");
}

Below is the output of approach 2 : Looks like it is re-directing to the login page?

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >


    <html lang="en-US">
       <head id="Head1"><meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1" /><link rel="Stylesheet" type="text/css" href="Public/Logon.css" /><title>
        Windows Azure SQL Reporting
    </title></head>
       <body >
          <form name="Logon" method="post" action="logon.aspx?ReturnUrl=%2fReportServer%3f%252fDemo2.rdl%26rs%3aCommand%3dRender%26rs%3aFormat%3dXML&amp;%2fDemo2.rdl&amp;rs%3aCommand=Render&amp;rs%3aFormat=XML" id="Logon">
    <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/XXXX" />

    <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/YYYY" />

            <h1 id="Title"><span id="LblTitleContent">Windows Azure</span></h1>
            <hr />
            <div class="ClsIntro">
                <span id="LblIntro"></span>
            </div>
            <div class="ClsInput">
                <div>
                    <label for="TxtUser" id="LblUser">User name</label>
                </div>
                <div>
                    <input name="TxtUser" type="text" id="TxtUser" tabindex="1" />
                </div>
            </div>
            <div class="ClsInput">
                <div>
                    <label for="TxtPwd" id="LblPwd">Password</label>
                </div>
                <div>
                    <input name="TxtPwd" type="password" id="TxtPwd" tabindex="2" />
                </div>
            </div>
            <div class="ClsSignIn">
                <input type="submit" name="BtnLogon" value="Sign in" id="BtnLogon" tabindex="4" /><input type="image" name="BtnLogonArrow" id="BtnLogonArrow" tabindex="5" src="Public/WhiteRightArrow.png" alt="Sign in" align="baseline" border="0" />
            </div>
            <div class="ClsErrMsg">
                <span id="lblMessage"></span>
            </div>
            <hr />
          </form>
       </body>
    </html>

What could be the problem with the approach 2, are we missing any thing?

Update

I am quite new to this azure and web services. I might be asking some silly question. Here is what i tried:

  • I tried adding a "Service reference" to azure sql reporting server in my windows phone 7 project. One thing i noted was that i can not add the serice as "Web reference" as it is disabled in windows phone 7 application.
  • After adding serive to my app i am getting set of classes. And one of them is ReportExecutionServiceSoapClient;
  • ReportExecutionService is not available.
  • I am not quite sure on how to use ReportExecutionServiceSoapClient api to get the cookie which i can use for WebClient.
  • Any sample application on how to use these APIs would be great. I tried searching over internet but couldn't get more information.
  • Below is what i tried but the cookie count is null.

    ReportExecutionServiceSoapClient client = new ReportExecutionServiceSoapClient();
    void MainPage_Loaded(object sender, RoutedEventArgs e)
    {
        client.ClientCredentials.UserName.UserName = "XXXX";
        client.ClientCredentials.UserName.Password = "XXXX";
        client.CookieContainer = new CookieContainer();
        client.LogonUserCompleted += new EventHandler<System.ComponentModel.AsyncCompletedEventArgs>(client_LogonUserCompleted);
        client.LogonUserAsync("XXXX", "XXXX", "xxxx.reporting.windows.net");
    }
    
    void client_LogonUserCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
    {
        int count = client.CookieContainer.Count;  // NULL COOKIE COUNT!!!
    }
    

Below is ClientConfig file. I have added enableHttpCookieContainer="true".

    <configuration>
        <system.serviceModel>
            <bindings>
                <basicHttpBinding>
                    <binding name="ReportExecutionServiceSoap" maxBufferSize="2147483647"
                        enableHttpCookieContainer="true"
                             maxReceivedMessageSize="2147483647">
                        <security mode="Transport" />
                    </binding>
                </basicHttpBinding>
            </bindings>
            <client>
                <endpoint address="https://xxxx.reporting.windows.net:443/ReportServer/ReportExecution2005.asmx"
                    binding="basicHttpBinding" bindingConfiguration="ReportExecutionServiceSoap"
                    contract="SqlReportingService.ReportExecutionServiceSoap"
                    name="ReportExecutionServiceSoap" />
            </client>
        </system.serviceModel>
    </configuration>

  • Please let me know what is missing.

SOLVED - Finally i am able to download xml file from Azure Sql reporting server. - Below is the solution. - First add a service reference to the Sql reporting server. - Then do a ReportExecutionServiceSoapClient::LogonUserAsync. - Use the obtained cookie with the WebClient for further request.

     public class WebClientExtended : WebClient
            {
                private CookieContainer myContainer;
                private HttpWebRequest myRequest;
                [SecuritySafeCritical]
                public WebClientExtended()
                {
                }

                [SecuritySafeCritical]
                public WebClientExtended(CookieContainer containter) 
                { 
                    myContainer = containter; 
                }

                public CookieContainer Cookies
                {
                    get { return myContainer; }
                    set { myContainer = value; }
                }

                protected override WebRequest GetWebRequest(Uri address)
                {
                    myRequest = (HttpWebRequest)base.GetWebRequest(address);
                    myRequest.Method = "GET";
                    myRequest.CookieContainer = Cookies;
                    return myRequest;
                }

                protected override WebResponse GetWebResponse(WebRequest request, IAsyncResult result)
                {
                    return myRequest.EndGetResponse(result);
                }
            }

            ReportExecutionServiceSoapClient rs = new ReportExecutionServiceSoapClient();
            string servername = "XXXX.reporting.windows.net";
            string uname = "XXXX";
            string password = "XXXX";

            public void LoadReport()
            {
                rs.ClientCredentials.UserName.UserName = uname;
                rs.ClientCredentials.UserName.Password = password;
                rs.CookieContainer = new CookieContainer();
                rs.LogonUserCompleted += new EventHandler<System.ComponentModel.AsyncCompletedEventArgs>(rs_LogonUserCompleted);
                rs.LogonUserAsync(uname, password, servername);

            }

            void rs_LogonUserCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
            {
                WebClientExtended webClient = new WebClientExtended(rs.CookieContainer);
                webClient.Credentials = new NetworkCredential(uname, password, servername);
                webClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(webClient_DownloadStringCompleted);
                webClient.DownloadStringAsync(new Uri(String.Format("https://{0}/ReportServer?%2fDemo2.rdl&rs:Command=Render&rs:Format=XML", servername)));
            }

            void webClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
            {
                 MessageBox.Show(e.Result);
            }

解决方案

The ServerReport class will call the LogonUser method on the ReportExecutionService to get a Forms Authentication cookie which will be used in all other requests (like rendering to XML).

Using credentials on the WebClient in your WP7 application doesn't cover this. You have 2 options:

  • Try to get a cookie by calling LogonUser and use it in your WebClient
  • Don't use WebClient but render the report through the ReportExecutionService

Take a look at the Windows Azure SQL Reporting: using SOAP APIs blog post to get started with this service in SQL Azure.

这篇关于从SQL报告服务器下载的XML文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆