• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 985
  • Last Modified:

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

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
ashley2009
Asked:
ashley2009
  • 4
  • 3
1 Solution
 
JaccoCommented:
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
 
ashley2009Author Commented:
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
 
JaccoCommented:
Hm, seems they have a special file format for their viewer control. Looks like a encoding problem though...
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

 
JaccoCommented:
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
 
ashley2009Author Commented:
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
 
JaccoCommented:
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
 
ashley2009Author Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now