Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I got a small script in Perl that needs to be converted to C#. I want to use it in my C# Windows Form application. Does any know if there is an program to convert Perl to C# ?

Thanks in advance!

----------------------

use MIME::Base64;
use strict;
use SOAP::Lite;

# Instance
my $SNC_HOST = "http://website.com";
my $base64;
my $buf;

# upload and attach a file on the local disk, base 64 encode it into a string first
open(FILE, "c:/number_test.xls") or die "$!";
while (read(FILE, $buf, 60*57)) {
  $base64 .= encode_base64($buf);
}

# call the sub routine to attach
attach_incident();

sub attach_incident {
  # target the ecc_queue table
  my $soap = SOAP::Lite->proxy("$SNC_HOST/ecc_queue.do?SOAP");
  my $method = SOAP::Data->name('insert')->attr({xmlns => 'http://website.com'});

  # set the ecc_queue parameters
  my @params = (SOAP::Data->name(agent => 'AttachmentCreator'));
  push(@params, SOAP::Data->name(topic => 'AttachmentCreator') );

  # identify the file name and its mime type
  push(@params, SOAP::Data->name(name => 'number_test.xls:application/vnd.ms-excel') );

  # attach to the incident, specifying its sys_id
  push(@params, SOAP::Data->name(source => 'incident:dd90c5d70a0a0b39000aac5aee704ae8') );

  # set the payload to be the base 64 encoded string representation of the file
  push(@params, SOAP::Data->name(payload => $base64) );

  # invoke the web service
  my $result = $soap->call($method => @params);

  print_fault($result);

  print_result($result);
}

sub print_result {
  my ($result) = @_;

  if ($result->body && $result->body->{'insertResponse'}) {
    my %keyHash = %{ $result->body->{'insertResponse'} };
    foreach my $k (keys %keyHash) {
        print "name=$k   value=$keyHash{$k}\n";
    }
  }
}

sub print_fault {
  my ($result) = @_;

  if ($result->fault) {
    print "faultcode=" . $result->fault->{'faultcode'} . "\n";
    print "faultstring=" . $result->fault->{'faultstring'} . "\n";
    print "detail=" . $result->fault->{'detail'} . "\n";
  }
}

# use the itil user for basic auth credentials
sub SOAP::Transport::HTTP::Client::get_basic_credentials {
   return 'itil' => 'itil';
}
Posted
Updated 31-Mar-11 0:08am
v3
Comments
Michel [mjbohn] 31-Mar-11 5:21am    
I don't know any tool to do convert Perl to C#. But if it is realy a small script you could post it here and somebody might find a solution
Andreas Gieriet 12-Jan-12 14:32pm    
This seems to be a simple SOAP communication with some web service.
Trash the script, check the web service interface and write the submission of your MS-Excel file to that service from scratch. Far easier, since you program in C# on a higer level if it comes to SOAP and web services.

AFAIK, there is no such tool: the possibility of eval($string) makes it unlikely! If it is that small, I would suggest you will find it quicker to do it manually.
 
Share this answer
 
This looks like consuming a standard webservice. Just add a ServiceReference to your project and provide it with the URI to the webservices WSDL. VS will set up all types and methods of the Webservice.

With s.th. like
private ServiceReference1.YourServiceSoapClient _wsclient = new yourApp.ServiceReference1.YourServiceSoapClient();

you get an instance of your service.
With _wsclient.someWSmethod(x,y,z) you can invoke a method of this webservice
 
Share this answer
 
v2
Comments
Member 7762422 31-Mar-11 5:45am    
Thanks, I added the URI in my script? But how does VS set up all types and methods of the Webservice.
Michel [mjbohn] 31-Mar-11 6:04am    
As I said, you have to add a ServiceRefernece to your VS project first. The reference is asking for the URI. VS will create all Types and Methods from the WSDL of the Webservice.
JavaScript
#!/usr/bin/perl -w
use strict;
my %next;
BEGIN {
    @next{'0'..'9','A'..'Z'}= ('1'..'9','A'..'Z','0');
}
sub inc36 {
    my $add= "";
    my $dig;
    while(  not $dig= $next{chop($_[0])}  ) {
        $add .= $dig;
        if(  ! length($_[0])  ) {
            $dig= '1';
            last;
        }
    }
    $_[0] .= $dig . $add;
}
while(  <DATA>  ) {
    for(  split " "  ) {
        print "$_ + 1 = ";
        inc36( $_ );
        print $_,$/;
    }
}
 
Share this answer
 
v2
Comments
RaisKazi 23-Dec-11 2:08am    
Edited: Added "pre" tag.
## Example of using SMS Matrix HTTP API in Perl
## Sending Text-to-Speech message

use LWP::UserAgent;
use HTTP::Request::Common;

my $ua = LWP::UserAgent->new();
my $res = $ua->request
(
POST 'http://www.smsmatrix.com/matrix_tts',
Content_Type => 'application/x-www-form-urlencoded',
Content => [ 'username' => 'user@hotmail.com',
'password' => 'mypassword123',
'phone' => '12506063167', ## Phone number
'gender' => 'male', ## Optional ('female' is default)
'repeat' => 1, ## Optional (0 is default)
'language' => 'us', ## Optional ('us','fr' or 'es', 'us' is default)
'txt' => 'Adam, web server at location number two is down. Please come ASAP.' ]
);

if ($res->is_error) { die "HTTP Error\n"; }

print "Matrix API Response: " . $res->content . "\n\n";
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900