470,810 Members | 875 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Share your developer knowledge by writing an article on Bytes.

How to Pass an Array from Perl Soap::Lite to a C# Web Service

I had a lot of problems doing this, so when I finally got it to work, I thought I would share the wealth. I was really trying to pass a file from a Perl script to a C# web service, but it never worked. The best I could do was passing the contents of the file as an array, and even that was no picnic.

So you need to install Perl, and then the Soap::Lite package. I am working in both AIX and Windows.

Compose a Perl script ( myscript.pl ) like this:
Expand|Select|Wrap|Line Numbers
  1. # reference the Soap::Lite package and turn on tracing
  2. use SOAP::Lite +trace=>all;
  4. #  read the file you want to send into an array
  5. my $logFilename = 'myfile2.txt'; 
  6. open(DATA,"<$logFilename") or die "Can't open data";
  7. @lines = <DATA>;
  8. close(DATA);
  10. #  Create the Soap::Lite client   
  11. #  The "proxy" is the Dot Net asmx file you created in    Visual Studio for your web service
  12. #  The "uri" is the location of the web service.  I created an IIS Web Site and set the path to the Visual Studio source code of the web service
  13. #  The "on_action" method formats your soap request so Dot Net can read it
  15. my $client = SOAP::Lite->new();
  16. $client->proxy('');
  17. $client->uri('');
  18. $client->on_action(sub { join '/', @_ });
  20. #  Compose a Perl array with the arguments to your web service method.  The names of the arguments must exactly match your web service ( including case ).  There were many posts suggesting other decorations such as soap-encoding, arrayType, and size, but I found I didn't need them.
  22. my @params = ( SOAP::Data->name('logFileName')->value($logFilename)->type('string'),  
  23.      SOAP::Data->name('logArray')->value(\SOAP::Data->name('item' => @lines)->type('string'))
  24.               );
  26. #  Call your web service method and print the result 
  27. $som = $client->ReportError(@params);
  28. my $output = $som->result;
  29. print $output . "\n";
But all this still won't work unless you adjust some stuff in your Dot Net web service.

When you create your web service, you must set the namespace to the same value as the uri above:

[WebService(Namespace = "")]

As mentioned earlier, the arguments from your Perl script must be named exactly the same as the arguments defined in your web service method. If not, the argument will appear in your web service as null. Incorrect argument names are a prime source of errors!

You must define the array argument variable in your web service with a type of "object". Once it has entered your web service, you can turn it into an
array of XML nodes like so:

Expand|Select|Wrap|Line Numbers
  1.  Array array = arr as Array;
  3.  foreach (XmlNode node in array)
  4.  {
  5.    if (!WriteLogFile(node.InnerText)) break;
  6.  } 
Even worse, you need to decorate your web service methods with either [SoapRpcMethod] or [SoapDocumentMethod], whichever works! I dont understand this at all, since if I run my Perl script in AIX, I need [SoapRpcMethod], but when I run the same Perl script in Windows, I need [SoapDocumentMethod]. It may have something to do with the level of the Perl packages in each environment, but I am clueless, and I could care less now that it works.

One more item: to debug the Dot Net web service, open the project, build it, click Debug > Attach to Process > aspnet_wp.exe. If you dont see aspnet_wp.exe, open a web page on your server to start the process. Then execute your Perl script ( in either Aix or Windows ) > perl myscript.pl and Visual Studio should stop at your breakpoints!
Dec 6 '10 #1
0 6951

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by fliversen | last post: by
reply views Thread by Eric | last post: by
reply views Thread by kim123 | last post: by
2 posts views Thread by furrypop | last post: by
1 post views Thread by Gary W. Smith | last post: by
reply views Thread by gcwg | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.