Search This Blog

Monday, January 23, 2012

.NET C# Jasper Server SOAP Web Services using Microsoft.Web.Services2.dll

I had some problems connecting to Jasper server using SOAP web services and the standard library System.Web.Services.dll.

The solution uses basic connectivity, the runReport() method and Microsoft.Web.Services2.dll from “Web Services Enhancements 2.0 for Microsoft .NET Framework”. You can download the library here.

You need path to reference it Visual Studio:

C:\Program Files (x86)\Microsoft WSE\v2.0\Microsoft.Web.Services2.dll

Whole needed source is available here.

var jasperService = new JasperService("http://localhost:8088/jasperserver/services/repository");
var credentials = new NetworkCredential("perspectiv", "perspectiv");
jasperService.Credentials = credentials;

string requestXML = "[.....]";
                   
jasperService.runReport(requestXML);
var attachments = jasperService.ResponseSoapContext.Attachments;
if (attachments.Count > 0)
{
    var atach = attachments[0];
    var atachStream = atach.Stream;
    using (var fileStream = File.Create("C:\\test\\test.pdf"))
    {
        atachStream.CopyTo(fileStream);
    }
}

Microsoft.Web.Services2 401 Unauthorized

If you encountered this error using Web.Services2 from Microsoft just try:

var service = new JasperService("http://localhost:8088/jasperserver/services/repository");
var cred = new NetworkCredential("someUser", "somePass");
service.Credentials = cred;

If this does not work for you try:

SoapContext requestContext = service.RequestSoapContext;
UsernameToken userToken =
    new UsernameToken("someUser", "somePass",
                      PasswordOption.SendPlainText);
requestContext.Security.Tokens.Add(userToken);
requestContext.Security.Timestamp.TtlInSeconds = 86400;

Wednesday, January 11, 2012

Android delete national characters from SMS by default; Android send sms without polish characters

If you want to send sms without national characters (in other words delete polish or other weird characters from your sms) and save some money on sms bills try this on Android:

If you have Samsung Galaxy S2 (maybe some other Samsung devices as well):
- go to: SMS messages –> Settings –> Input mode –> GSM alphabet
(choose the option GSM alphabet instead of Unicode one and your smses will be sent without national characters)

If you have other devices:
- install “GO SMS Pro” from Market.

Gosms - setting – advanced settings – settings for sending - switch on national setting

This application has the option called:

“Localization support for accented chars: by enabling Czech, Polish and French SMS mode “ which will delete your national characters from smses in Android.

Tuesday, January 10, 2012

C# Using reflection to create an instance of a specific type; convert string to a specific type;

The idea behind the post is to convert a string such as: “System.Int32” to an instance of a specific type.
To create an instance of a compiled custom class in the assembly:

Assembly.GetExecutingAssembly().CreateInstance(YourCustomClassName);

To create an instance of a built-in type e.g. “System.Int32” :
Activator.CreateInstance(Type.GetType("System.Int32"));