简体   繁体   中英

How do I send this SOAP XML in Perl?

I have to send the XML below. And i have no idea where to start. I know i need to look up SOAP in Perl but thats roughly it.

<xs:element name="CheckDomain"> 
<xs:complexType> 
<xs:sequence> 
<xs:element name="domain" type="domainRef"/> 
<xs:element name="suggestions" type="xs:boolean" default="false" minOccurs="0"/> 
</xs:sequence> 
</xs:complexType> 
</xs:element>

Where to start? Start reading the documentation for SOAP::Lite ; there are more expansive SOAP handling libraries here .

If you need more help, you may find what you need in some of the earlier questions on SOAP at Stackoverflow.

The XML snippet you posted looks like XSD schema. It describes the following XML:

<CheckDomain xmlns="...">
 <domainRef>...</domainRef>
 <suggestions>true</suggestions> <!-- or it could be "false" -->
</CheckDomain>

The snippet you provided does not say what namespace CheckDomain needs to be, or what's supposed to be inside of domainRef. You need the whole XSD document for this.

Also, without seeing the WSDL file for the service, it's impossible to tell how to turn this into a valid SOAP message. (Assuming that you're dealing with a real SOAP service, and not just with a REST or XML-RPC service that happens to describe its input using XSD schema).

The beauty of SOAP is that you usually never have to do any of this manually. You just get the right tool and point it at the WSDL and XSD files published by the service, and you automatically have classes generated that do the right thing.

Well, you could get an HTTP client on CPAN, then just use a << (here documents) with (XML encoded values) interpolated variables to send the request. Then you would need to parse the response.

There should be a SOAP client for Perl, but that's not a combination I've encountered.

Interesting question, though. Good luck with the WSDL bludgeoning :-)

check the following url in how to use perl to send soap messages :

http://users.skynet.be/pascalbotte/rcx-ws-doc/perlpost.htm

saludos,

Use The LWP::UserAgent which is a class implementing a web user agent. LWP::UserAgent objects can be used to dispatch web requests.

use strict;
use LWP::UserAgent;
use HTTP::Request;

my $message = "<?xml version=\"1.0\" encoding=\"utf-8\"?>
               <soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" 
                xmlns:ecn=\"http://www.alcatel.com/ecn_csa/EcnServices.wsdl\">
               <soapenv:Body>
               <ecn:GetBusinessAccount>
               <accountNumber>$number</accountNumber>
               </ecn:GetBusinessAccount>
               </soapenv:Body>
               </soapenv:Envelope>";
my $userAgent = LWP::UserAgent->new();
my $request = HTTP::Request->new(POST => 'http://server:port/endpoint');
# $request->header(SOAPAction => '""'); #use it if required
$request->content($message);
$request->content_type("text/xml; charset=utf-8");
my $response = $userAgent->request($request);
# $response->code == 200
print $response->as_string;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM