Solved

How to Convert Base64Binary Output of a Web Service to the original document and display it in a asp .net webpage

Posted on 2011-02-21
7
947 Views
Last Modified: 2012-05-11
Hello,
I have a question on conversion of byte[] to string in web service project by using .NET C#.

My project is like this:

First Part:

1) Active Report: An active report that uses an XML file and the Active Report would get showed in web page as a
web service as a binary base 64 format ( see screen shot#1) --- works and I can see base64Binary output.

The next part  is:

2) Web Page: Showing Active Report by the Web Viewer in 1 Div --- this works also (see screen shot #2)
                       : Would also show Active Report that comes from the Web Service in another Div --- this does not work
                         as the rendering is not happening properly ( conversion to original format is not happening)
                         (please see screen shot # 2)

The code for web service, Default.aspx.cs, ActiveReport.cs file, xml file is attached.

*** If you observe the output that gets displayed in Div1, you can see 4¿.¿7¿2¿ ¿i¿n¿c¿h¿e¿s (4.72 inches)or information like this, means values are still getting transferred from web service but not getting displayed properly.

Basically both of the Div would show exactly the same display. Though Div1's content coming from web service, the content is actually of the same Activereport1 thats getting displayed in Div2.

Please help, suggest, advice .... And if you think I am not understanding something, also let me know that as well.
     base64Binary_How to convert
WebService.cs
-----------------------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;


[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class WebService3 : System.Web.Services.WebService {
    public WebService3 () {
    }

    [WebMethod(Description = "Returns a products report grouped by category")]
    public Byte[] GetRainInfo()
    {
        NewActiveReport1 rpt = new NewActiveReport1();
        rpt.Run();
        return rpt.Document.Content;
    }
}

==========================================================
Default.aspx.cs
-----------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using localhost;
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        localhost.WebService3 binWS = new localhost.WebService3();
        byte[] b = binWS.GetRainInfo();
        System.Text.Encoding enc = System.Text.Encoding.UTF8;
        string myString = enc.GetString(b);
        Div1.InnerHtml = myString;
    }
}
===========================================================
NewActiveReport1.cs
---------------------------
using System;
using System.Drawing;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using DataDynamics.ActiveReports;
using DataDynamics.ActiveReports.Document;

/// <summary>
/// Summary description for NewActiveReport1.
/// </summary>
public class NewActiveReport1 : DataDynamics.ActiveReports.ActiveReport
{
    private TextBox txtMonth1;
    private TextBox txtRain1;
    private DataDynamics.ActiveReports.Detail detail;

	public NewActiveReport1()
	{
		//
		// Required for Windows Form Designer support
		//
		InitializeComponent();
	}

	/// <summary>
	/// Clean up any resources being used.
	/// </summary>
	protected override void Dispose( bool disposing )
	{
		if( disposing )
		{
		}
		base.Dispose( disposing );
	}

	#region ActiveReport Designer generated code
	/// <summary>
	/// Required method for Designer support - do not modify
	/// the contents of this method with the code editor.
	/// </summary>
	private void InitializeComponent()
	{
        System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Resources.NewActiveReport1));
        DataDynamics.ActiveReports.DataSources.XMLDataSource xmlDataSource1 = new DataDynamics.ActiveReports.DataSources.XMLDataSource();
        this.detail = new DataDynamics.ActiveReports.Detail();
        this.txtMonth1 = new DataDynamics.ActiveReports.TextBox();
        this.txtRain1 = new DataDynamics.ActiveReports.TextBox();
        ((System.ComponentModel.ISupportInitialize)(this.txtMonth1)).BeginInit();
        ((System.ComponentModel.ISupportInitialize)(this.txtRain1)).BeginInit();
        ((System.ComponentModel.ISupportInitialize)(this)).BeginInit();
        // 
        // detail
        // 
        this.detail.ColumnSpacing = 0F;
        this.detail.Controls.AddRange(new DataDynamics.ActiveReports.ARControl[] {
            this.txtMonth1,
            this.txtRain1});
        this.detail.Height = 0.3645834F;
        this.detail.Name = "detail";
        // 
        // txtMonth1
        // 
        this.txtMonth1.DataField = "Month";
        this.txtMonth1.Height = 0.2F;
        this.txtMonth1.Left = 0F;
        this.txtMonth1.Name = "txtMonth1";
        this.txtMonth1.Text = "txtMonth1";
        this.txtMonth1.Top = 0F;
        this.txtMonth1.Width = 1F;
        // 
        // txtRain1
        // 
        this.txtRain1.DataField = "Rain";
        this.txtRain1.Height = 0.2F;
        this.txtRain1.Left = 1F;
        this.txtRain1.Name = "txtRain1";
        this.txtRain1.Text = "txtRain1";
        this.txtRain1.Top = 0F;
        this.txtRain1.Width = 1F;
        // 
        // NewActiveReport1
        // 
        this.MasterReport = false;
        xmlDataSource1.FileURL = "C:\\Users\\sharmin\\Documents\\Visual Studio 2010\\Projects\\DocumentWebService1\\rainFa" +
            "ll.xml";
        xmlDataSource1.RecordsetPattern = "//Info";
        this.DataSource = xmlDataSource1;
        this.PageSettings.PaperHeight = 11F;
        this.PageSettings.PaperWidth = 8.5F;
        this.PrintWidth = 2.114583F;
        this.Sections.Add(this.detail);
        this.StyleSheet.Add(new DDCssLib.StyleSheetRule("font-family: Arial; font-style: normal; text-decoration: none; font-weight: norma" +
                    "l; font-size: 10pt; color: Black", "Normal"));
        this.StyleSheet.Add(new DDCssLib.StyleSheetRule("font-size: 16pt; font-weight: bold", "Heading1", "Normal"));
        this.StyleSheet.Add(new DDCssLib.StyleSheetRule("font-family: Times New Roman; font-size: 14pt; font-weight: bold; font-style: ita" +
                    "lic", "Heading2", "Normal"));
        this.StyleSheet.Add(new DDCssLib.StyleSheetRule("font-size: 13pt; font-weight: bold", "Heading3", "Normal"));
        ((System.ComponentModel.ISupportInitialize)(this.txtMonth1)).EndInit();
        ((System.ComponentModel.ISupportInitialize)(this.txtRain1)).EndInit();
        ((System.ComponentModel.ISupportInitialize)(this)).EndInit();

	}
	#endregion
}
==========================================================
rainFall.xml
---------------
<?xml version="1.0" encoding="utf-8" ?>
<RainFallInfo>
  <Info>
    <Month>
      January
    </Month>
    <Rain>
      4.72 inches
    </Rain>
  </Info>
  <Info>
    <Month>
    February
    </Month>
    <Rain>
      4.15 inches
    </Rain>
  </Info>
  <Info>
    <Month>
      March
    </Month>
    <Rain>
      3.40 inches
    </Rain>
  </Info>
  <Info>
    <Month>
      April
    </Month>
    <Rain>
      1.25 inches
    </Rain>
  </Info>
  <Info>
    <Month>
      May
    </Month>
    <Rain>
      0.54 inches
    </Rain>
  </Info>
  <Info>
    <Month>
    June
    </Month>
    <Rain>
    0.13 inches
    </Rain>
  </Info>
  <Info>
    <Month>
    July
    </Month>
    <Rain>
    0.04 inches
    </Rain>
  </Info>
  <Info>
    <Month>
    August
    </Month>
    <Rain>
    0.09 inches
    </Rain>
  </Info>
  <Info>
    <Month>
    September
    </Month>
    <Rain>
    0.28 inches
    </Rain>
  </Info>
  <Info>
    <Month>
    October
    </Month>
    <Rain>
    1.19 inches
    </Rain>
  </Info>
  <Info>
    <Month>
    November
    </Month>
    <Rain>
    3.31 inches
    </Rain>
  </Info>
  <Info>
    <Month>
  December
    </Month>
    <Rain>
  3.18 inches
    </Rain>
  </Info>
</RainFallInfo>
===========================================================

Open in new window

Default.aspx
Default.aspx.cs
WebService.cs
NewActiveReport1.cs
rainFall.xml
base64BinaryWebServiceReturnValu.jpg
0
Comment
Question by:ashley2009
  • 4
  • 3
7 Comments
 
LVL 10

Expert Comment

by:Jacco
ID: 34943392
I think the report content is Unicode.

Try using following code
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        localhost.WebService3 binWS = new localhost.WebService3();
        byte[] b = binWS.GetRainInfo();
        System.Text.Encoding enc = System.Text.Encoding.Unicode;
        string myString = enc.GetString(b);
        Div1.InnerHtml = myString;
    }
}

Open in new window

0
 
LVL 3

Author Comment

by:ashley2009
ID: 34943568
Hello,

thank you for your response; I followed your suggestion, but I still get incoherent output. The new type of output is attached.

Any more suggestion, advice?
StillIncoherentOutPut.jpg
0
 
LVL 10

Expert Comment

by:Jacco
ID: 34943825
Hm, seems they have a special file format for their viewer control. Looks like a encoding problem though...
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 10

Accepted Solution

by:
Jacco earned 500 total points
ID: 34943892
I think you have to use the WebViewer control included in their PRO version of the ActiveReports tool.

Then do something like

viewer1.Report.Document.Contents = ...

Regards, Jacco
0
 
LVL 3

Author Comment

by:ashley2009
ID: 34944042
Hello,

response for  02/21/11 08:00 AM, ID: 34943825:

do you think it is the issue of Active Report Application Type? I guess so as though the data gets transmitted the Viewer is missing. I will try to ask DataDynamic/Grape City, but I cannot log in to their forum.


response for 02/21/11 08:08 AM, ID: 34943892:

not sure why and how I would use viewer1.Report.Document.Contents and will put fetched return binary64string value in the viewer. By the way, the binary64string definitely has the Activereport application information inside those binary values ...
I thought we only use that type of line when we directly specify a report in a web page.  

Please Jacco and everyone, give me your suggestions and insights. Do you think that this is even possible ( in my this project scenario)?

I



0
 
LVL 10

Expert Comment

by:Jacco
ID: 34949088
The viewer is only included in the PRO version.

Do you have that version?

I don't have the tool so can't really try my code.

Regards, Jacco
0
 
LVL 3

Author Comment

by:ashley2009
ID: 34988516
Yes, I have that version, and you are right. Last week I did not understand as I thought the viewer would be also converted to binary, but it is not possible as the viewer does not come with browser ( the way we can install pdf or flash viewer in browser, and if it is installed, we can view documents in pdf or in flash).


0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question