<div dir="ltr"><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px">Hi,</p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px"> </p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px">
I have been using XML::Compile::SOAP to interface with several webservices using XOP and have been able to upload with no issues. </p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px"> </p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px">
But now I am having some problems extracting the returned XOP document(s). </p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px"> </p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px">
Could anyone please point me to an example of extracting MTOM attachments using XML::Compile::SOAP?</p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px"> </p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px">
I've been successful in doing it by using trace with a different webservice but I am using a new webservice and my method is not working. </p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px"> </p>
<p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px">The actual script is too long to include and requires authorization – so I am only including how I am making the call here:</p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px">
</p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px">use XML::Compile::WSDL11; # use WSDL version 1.1</p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px">use XML::Compile::SOAP11; # use SOAP version 1.1</p>
<p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px">use XML::Compile::SOAP12; # use SOAP version 1.2</p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px">use XML::Compile::Transport::SOAPHTTP;</p>
<p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px">use XML::Compile::XOP;</p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px"> </p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px">
my $xml_compile = XML::Compile::WSDL11->new($primary_wsdl, schema_dirs => \@schema_dirs)</p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px"> || die "[Error] UNABLE TO CREATE XML::Compile::WSDL11 OBJECT";</p>
<p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px"> </p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px">my $ua = LWP::UserAgent->new();</p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px">
</p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px">$ua->ssl_opts(verify_hostname => 0, keep_alive => 1);</p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px">$ua->cookie_jar( {file => $jar_file, autosave => 1, ignore_discard => 1 });</p>
<p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px"> </p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px">my $trans = XML::Compile::Transport::SOAPHTTP->new(user_agent => $ua, soap => 'SOAP11');</p>
<p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px"> </p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px">my $call = $xml_compile->compileClient($operation_name, port => $service_port, trans => $trans);</p>
<p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px"> </p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px">my %get_request_params = (%data);</p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px">
my $request_params = get_request_params(%get_request_params);</p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px"> </p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px">
my @request_params = (parameters => $request_params);</p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px">my ($answer, $trace) = $call->(@request_params);</p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px">
</p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px">Which results in a successful call:</p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px"> </p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px">
ANSWER: $VAR1 = {</p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px"> 'parameters' => {</p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px"> 'Result' => {</p>
<p class="MsoNormal" style="margin-left:0.5in;font-family:arial,sans-serif;font-size:13px;text-indent:0.5in"> 'SignedDocument' => {</p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px">
'InitialContentEncoding' => 'MIME',</p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px"> 'DocumentFormat' => 'OTHER',</p>
<p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px"> 'Data' => bless( do{\(my $o = 63420456)}, 'XML::LibXML::Element' ),</p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px">
'ImplicitSignatureInfo' => {</p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px"> 'SignatureFormat' => 'PKCS7',</p>
<p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px"> 'AuditCategory' => 'CADESA'</p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px">
}</p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px"> }</p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px">
} </p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px"> },</p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px">
'{<a href="http://www.trustweaver.com/trustarchive%7DRequestId" target="_blank">http://www.trustweaver.com/trustarchive}RequestId</a>' => bless( do{\(my $o = 63419928)}, 'XML::LibXML::Element' )</p>
<p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px"> };</p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px"> </p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px">
And how I have been extracting MTOM objects in another webservice:</p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px"> </p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px">
# get all of the MTOM data objects and index by the content id from the header</p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px">my @received_files;</p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px">
</p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px">my $req = $trace->request; # HTTP message which was sent</p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px">my $res = $trace->response; # HTTP message received</p>
<p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px"> </p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px">my @parts = $res->parts;</p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px">
</p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px">foreach (@parts) {</p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px"> </p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px">
my $part = $_;</p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px"> </p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px"> my $headers = $part->headers;</p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px">
</p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px"> if ($headers->header('Content-Type') eq 'application/octet-stream' &&</p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px">
$headers->header('Content-Transfer-Encoding') eq 'binary' ) {</p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px"> </p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px">
my %file;</p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px"> </p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px"> my $cid = $headers->header('Content-ID');</p>
<p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px"> $cid =~ s/^<//;</p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px"> $cid =~ s/>$//;</p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px">
</p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px"> my $xop = XML::Compile::XOP::Include->new(bytes => $part->content, cid => $cid);</p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px">
</p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px"> $file{cid} = $cid;</p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px"> $file{xop} = $xop;</p>
<p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px"> $file{filename} = $filename;</p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px"> </p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px">
push(@received_files, \%file);</p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px"> </p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px"> }</p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px">
</p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px">}</p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px"> </p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px">
foreach (@received_files) {</p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px"> </p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px"> my $file = $_;</p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px">
</p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px"> my $cid = $file->{cid};</p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px"> my $xop = $file->{xop};</p>
<p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px"> </p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px"> my $filename = $file->{filename};</p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px">
</p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px"> my $target_filepath = "$target_directory/$filename";</p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px">
</p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px"> if ($xop->write($target_filepath)) {</p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px"> </p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px">
print "WROTE FILE [$filename] TO [$target_filepath]\n";<br></p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px"> </p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px">
} else {</p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px"> </p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px"> print "[Error] UNABLE TO WRITE FILE [$filename] TO [$target_filepath]\n";<br>
</p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px"> </p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px"> }</p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px">
</p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px">}</p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px"> </p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px">
And I am also getting the XOP lose message:</p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px"> </p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px"> warning: loosing received XOPs</p>
<p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px"> </p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px">But I cannot seem to get the extraction done correctly.</p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px">
</p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px">Any help or pointers is greatly appreciated.</p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px"> </p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px">
Thank you!</p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px"> </p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px">Christopher Taranto</p><p class="MsoNormal" style="font-family:arial,sans-serif;font-size:13px">
</p></div>