Solved

soap::lite  passing xml data to perl script.

Posted on 2008-10-20
13
940 Views
Last Modified: 2013-11-05
Hi, I am writing a soap::lite client to send/receive xml request to a .net web service.
problem is the xml request is getting very complicated and deep. Its there a way to import a pre made xml file to the perl script and have the script create the body of the request from the xml file?
Thanks rob.
0
Comment
Question by:robids
  • 5
  • 4
  • 3
  • +1
13 Comments
 
LVL 10

Expert Comment

by:MadShiva
ID: 22767028
Hi !

I'm not sure what you want do.

Maybe with the module : XML::Parser

Best Regards
0
 

Author Comment

by:robids
ID: 22767061
Hi.  I need to send/receive xml request to a .net web service using soap:lite
below is the xml file that i need to send via soap::lite to the .net web sevice.
###
<Ver1.0>

<Header>
<LicenseId>2231</LicenseId>
<SiteId>201</SiteId>
<DeviceId>34401</DeviceId>
<UserName>11190017</UserName>
<Password>017</Password>
<SiteTrace>0001</SiteTrace>
</Header>

<Transaction>

<CreditAuth>

<Block1>

<CardData>

<TrackData method="swiped">
B4012002000060016 VI TEST CREDIT251210118039000000000396
                     
</TrackData>
</CardData>
<Amt>25</Amt>
<CPCReq>N</CPCReq>
<AllowDup>Y</AllowDup>

<AutoSubstantiation>

<FirstAdditionalAmtInfo>
<AmtType>4S</AmtType>
<Amt>60.00</Amt>
</FirstAdditionalAmtInfo>

<SecondAdditionalAmtInfo>
<AmtType>4V</AmtType>
<Amt>30.00</Amt>
</SecondAdditionalAmtInfo>
<AllowPartialAuth>Y</AllowPartialAuth>
<MerchantVerificationValue>123abc456d
                                </MerchantVerificationValue>
</AutoSubstantiation>
</Block1>
</CreditAuth>
</Transaction>
</Ver1.0>
###

how do i pass this xml file to the perl script???
thanks
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 22767268
> how do i pass this xml file to the perl script???
no, you perl script reads the file content and passes it as HTTP message body to the corresponding URL
0
 

Author Comment

by:robids
ID: 22769168
OK, Thats my question. How is this done?. I need to pass the data to the script so the data can be sent via the soap::lite mxl request to the .net webserver.
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 22769807
as long as you do not provide the code you have done so far it's difficult to give you proper samples. Probably following helps you:
   if (open(X,";
     SOAP::Data->name("yourdata" => $xml);
    # .. your other code
   }
0
 

Author Comment

by:robids
ID: 22770027
Thank you here is my code.
#!/usr/bin/perl

###my $WSDL="https://site.net/PosGatewayService.asmx?wsdl=wsdl1";

my $NS = "http://site.net/PosGatewayService/";

my $HOST = "https://site.net/PosGatewayService.asmx";
 

use strict;

use SOAP::Lite +trace => qw (debug);
 

my $search = SOAP::Lite

#->readable(1)

#->xmlschema('http://www.w3.org/2001/XMLSchema')

->on_action( sub { return '""';} )

->proxy($HOST)

->uri($NS);
 

my $method =  ### pull in xml file ###

my $results = $search->call($method  );

print $results;

Open in new window

0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 39

Accepted Solution

by:
Adam314 earned 125 total points
ID: 22771863
Use this for your line 16
my $method;

open(my $in, "<your_xml_file.xml") or die "Could not open xml: $!\n";

{local $/;

$method=<$in>;

}

close($in);

Open in new window

0
 

Author Comment

by:robids
ID: 22771969
wow that's it except the output request is turned into the following:

<Amt>25</Amt> &#xd;
instead of
<Amt>25</Amt>

can the be formatted?
0
 
LVL 39

Expert Comment

by:Adam314
ID: 22772531
The above will read the your_xml_file.xml into $method.  No modification is done - the file is read exactly as it is.

I'm not sure what you want to do.... but to remove "&#xd;" you could use this:
    $var =~ s/&#xd;//;
Replace $var with whatever variable has the data.
0
 

Author Closing Comment

by:robids
ID: 31508108
Thank You.
 The problem is with what the soap::lite does to the imported xml data. The soap envenlope gets changed to <Amt>25</Amt> &#xd; in stead of what is pass to the scrip 25 on the output.  I need to get the output formatted correctly. Thanks again for your help
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 22790745
hmm, what is the big difference between my suggestion and the graded one, may be I'm too blind for that ...
0
 
LVL 39

Expert Comment

by:Adam314
ID: 22791305
Yes, they are very similar.  I would be okay with a split.
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 22803893
Adam314, my wondering was meant for the questioner ;-)
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
OTRS Installation 1 276
Perl - Mawk 2 69
syslog unix file 20 62
Perl Script to read file contents, make changes, and build new file 7 82
I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now