Oh man...some days it pays to read the error message.....
...Unexpected element encountered in the input XML document...
D'OH!!!!!
Uhhh, ya, you have to specify the XML parameter correctly...
Attachment1_attachmentName-->Works
Attachment_1_attachmentName-->does not work
So the code I had written yesterday did work, I just "assumed" it was how I was
encoding the data from the file.
For those that are interested if you want to have a Perl CGI Script to pass an
attachment to a Web Service this is how it's done:
use CGI;
use File::Basename;
use File::stat;
use MIME::Base64 qw(encode_base64);
my $cgi=new CGI;
print ($cgi->header());
print ($cgi->start_html("Create Request Questions"));
$filename = $cgi->param('Attachment');
$upload_filehandle = $cgi->upload('Attachment');
my $username = ''; #
ARS_LoginName_to_use
my $password = ''; #
password_for_above_Login_Name
my $authentication= ''; # Extra authentication
value (NT domain type stuff)
my $locale= ''; # Language
setting for this client
my $timeZone= ''; # ARS timezone
setting for this connection(client timezone)
my
$proxy='http://<ARSERVER>/arsys/services/ARService?server=<ARSERVER>&webService=<Web
Service Name>';
my $uri=<Web Service Name>Service';
use SOAP::Lite;
my $header = SOAP::Header->name('AuthenticationInfo' =>
\SOAP::Header->value(
SOAP::Header->name('userName'
=> $username)->type(''),
SOAP::Header->name('password'
=> $password)->type(''),
SOAP::Header->name('authentication' => $authentication)->type(''),
SOAP::Header->name('locale' =>
$locale)->type(''),
SOAP::Header->name('timeZone'
=> $timeZone)->type(''),
)
);
if ( !$filename )
{
print $cgi->header ( );
print "There was a problem uploading your file";
exit;
}
($name, $path, $extension) = fileparse($filename, '\..*' );
$Attach_Name = $name . $extension;
$Attach_Size = stat($filename)->size;
open(FILE,$upload_filehandle) or die "$!";
while (read(FILE, $buf, 60*57)) {
$Attach_Data = $Attach_Data.encode_base64($buf);
}
close(FILE);
$File_Name = SOAP::Data->name('Attachment1_attachmentName') ->
value($Attach_Name)->type('xsd:string');
$File_size = SOAP::Data->name('Attachment1_attachmentOrigSize')
-> value($Attach_Size)->type('xsd:int');
$File_Data = SOAP::Data->name('Attachment1_attachmentData') ->
value($Attach_Data)->type('xsd:base64Binary');
$soap = new SOAP::Lite
proxy=>$proxy, uri=>$uri;
$result=$soap->CreateAttachRequest($File_Name, $File_Data,
$File_size);
HTH
Matt P.
From: Matthew Perrault
Sent: Wednesday, August 04, 2010 11:18 AM
To: '[email protected]'
Subject: passing attachments in via Web Service with Perl CGI
All,
Ok here's another one that I've been looking at for a couple of days now.
I've got a Web Service/XML page that is setup to handle Attachments.
When Remedy built the XML page it set the Attachment Data element as type:
XSD:Base64Binary
I have a Perl CGI script to consume the WebService.
I can get it to work when I'm not passing an attachment.
The problem is I can't seem to get the Attachment Data converted to the correct
Data Type.
I can get the file name and Size, just not the Data Type
I keep getting the error:
Fault :ERROR (8962): Unexpected element encountered in the input XML document;
Faultcode :soapenv:Server.userException Faultdetail :hostname<SERVER NAME>
I've tried passing just the file,
The file handle,
Opening the File and reading all the lines into a buffer, and passing that.
I've tried to encode it:
open(FILE,$upload_filehandle) or die "$!";
while (read(FILE, $buf, 60*57)) {
$Attach_Data.= encode_base64($buf);
# print encode_base64($buf);
}
close(FILE);
and none of those have worked.
I'm starting to look at using the Pack function to convert it to a Binary Array,
But can't quite figure out how to do that, yet.
Has anyone been able to setup a Perl CGI to consume a Web Service and pass an
attachment through?
Any suggestions on how I can get the Perl CGI to convert that Attachment Data
to the correct format?
Thanks in Advance
Matt P.
_______________________________________________________________________________
UNSUBSCRIBE or access ARSlist Archives at www.arslist.org
attend wwrug10 www.wwrug.com ARSlist: "Where the Answers Are"