|
NAMEXML::Compile::SOAP::Daemon - SOAP accepting server (base class)INHERITANCEXML::Compile::SOAP::Daemon is extended by XML::Compile::SOAP::Daemon::AnyDaemon XML::Compile::SOAP::Daemon::CGI XML::Compile::SOAP::Daemon::NetServer XML::Compile::SOAP::Daemon::PSGI SYNOPSIS#### have a look in the examples directory! use XML::Compile::SOAP::Daemon::CGI; my $daemon = XML::Compile::SOAP::Daemon::CGI->new; # operation definitions from WSDL my $wsdl = XML::Compile::WSDL11->new(...); $wsdl->importDefinitions(...); # more schemas $daemon->operationsFromWSDL($wsdl, callbacks => ...); $daemon->setWsdlResponse($wsdl_fn); $daemon->setWsdlResponse($wsdl_fn, $soap11->mediaType); # operation definitions added manually my $soap11 = XML::Compile::SOAP11::Server->new(schemas => $wsdl->schemas); my $handler = $soap11->compileHandler(...); $daemon->addHandler('getInfo', $soap11, $handler); DESCRIPTIONThis base class implements the common needs between various types of SOAP daemons. Ache daemon can handle various kinds of SOAP protocols at the same time, when possible hidden from the user of this module.The following extensions are implemented on the moment:
If you have a WSDL describing your procedures (operations), then the only thing you have to worry about is adding callbacks for each of the defined ports. Without WSDL, you will need to do more manually, but it is still relatively simple to achieve. Do not forget to take a look at the extensive example, enclosed in the XML::Compile::SOAP::Daemon distribution package. It is really worth the time. METHODSConstructors
Attributes
Running the server
Preparations
example: $daemon->operationsFromWSDL($wsdl, service => 'MyService', binding => 'MyService-soap11', callbacks => {get => \$f11}); $daemonwsdl->operationsFromWSDL($wsdl, service => 'MyService-test', binding => 'MyService-soap12', callbacks => {get => \$f12});
Helpers
DETAILSOperation handlersPer operation, you define a callback which handles the request. There can also be a default callback for all your operations. Besides, when an operation does not have a handler defined, one is created for you.sub my_callback($$$) { my ($soap, $data_in, $request) = @_; return $data_out; } The $soap parameter is the actual "XML::Compile::SOAP" object which handles this protocol version (at the moment only XML::Compile::SOAP11. $data_in is a HASH with the decoded information from the request. The type and content of $request depends on the type of server, often an HTTP::Request. The $data_out is a nested HASH which will be translated in the right XML structure. This could be a Fault, like shown in the next section. Please take a look at the scripts in the examples/ directory within the distribution. Returning errorsIn WSDLs you may find explicitly defined error details types. There is only one such error structure per operation: when an operation may return different kinds of errors, they will be wrapped into one structure which contains the details. See section "Returning private errors" below.Errors which do not return an "details" record can always be reported with code and string. Let's first explain those. Returning general errors To have a handler return an error, leave the callback with something like this: use XML::Compile::Util qw/pack_type/; sub my_callback($$) { my ($soap, $data) = @_; my $code = pack_type $my_err_ns, 'error-code'; return +{ Fault => { faultcode => $code , faultstring => 'something is wrong' , faultactor => $soap->role } , _RETURN_CODE => 404 , _RETURN_TEXT => 'sorry, not found' }; } Fault codes are "prefix:error-name", XML::Compile finds the right prefix based on the URI. If your error namespace is not mentioned in the WSDL or other loaded schemas, you should use XML::Compile::WSDL11 subroutine prefixes first. SOAP uses error codes in the SOAPENV namespace. It shows whether errors are client or server side. This is produced like: use XML::Compile::SOAP::Util 'SOAP11ENV'; $code = pack_type SOAP11ENV, 'Server.validationFailed'; [release 2.02] Fields "_RETURN_CODE" and "_RETURN_TEXT" can be used to change the HTTP response (and maybe other protocol headers in the future). These can also be used with valid answers, not limited to errors. There is no clear definition how SOAP faults and HTTP return codes should work together for user errors. Be warned that WCF (MicroSoft's .NET) interprets the return code in SOAP1.2 style, not SOAP1.1. The 1.2 specification says that only _RETURN_CODE 200 and 202 can contain a SOAP respons. Other servers will code the content for any 2xx code. Returning private errors In a WSDL, we can specify own fault types. These defined elements describe the "detail" component of the message. For example, in the WSDL and Schema we may have: <xs:element name="errorReportMsg" type="ErrorReportType"/> <xs:complexType name="ErrorReportType"> <xs:sequence> <xs:element name="info" type="string"> <xs:element name="cause" type="string" minOccurs="0"> </xs:sequence> </xs:complexType> <message name="ErrorReport"> <part name="message" element="tmdd:errorReportMsg"/> </message> <operation name="GetData"> <input message="GetDataRequest"/> <output message="GetDataRequest"/> <fault name="errorReport" message="ErrorReport"/> </operation> To return a private error you need to determine the name of the fault part. In the example above the fault parts name is "errorReport". However, in some WSDLs the "name" option is not present and XML::Compile::SOAP assumes that "fault" will be used to indicate the fault part. You need to return a HASH with values for the ErrorReport element together with values for the fields in the Fault value shown in the previous section. For example: my $msg = "Unknown Error"; return +{ errorReport => # the name of the fault part { # this gets put into the 'detail' part of # the fault message info => $msg # these are used for the other parts of the fault message , faultcode => pack_type(SOAP11ENV, 'Server.BadOperation') , faultstring => $msg , faultactor => $soap->role } }; If no name is specified for the fault part, then you can use: return +{ fault => # the name of the fault part { faultcode => pack_type(SOAP11ENV, 'Server.BadOperation') , faultstring => $msg , faultactor => $soap->role , detail => { info=> $msg } } }; It has been observed that several SOAP toolkits do not handle user defined faults messages very well. However, they do provide the faultcode and faultstring values from the fault message. SEE ALSOThis module is part of XML-Compile-SOAP-Daemon distribution version 3.14, built on May 11, 2018. Website: http://perl.overmeer.net/CPAN/LICENSECopyrights 2007-2018 by [Mark Overmeer <markov@cpan.org>]. For other contributors see ChangeLog.This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See http://dev.perl.org/licenses/
Visit the GSP FreeBSD Man Page Interface. |