SOAP::Server(3)
πΈ NAME πΈ
SOAP::Server β provides the basic framework for the transport-specific server classes to build upon.
okay so this is the SOAP::Server(3) page from User Contributed Perl Documentation, and the manual name is right here at the top like a little name tag π. Bestie, this class is the base vibe: it gives transport-specific server classes the basic framework they build on top of.
π DESCRIPTION π
The SOAP::Server class provides the basic framework for the transport-specific server classes to build upon. Huge note: in none of the code examples provided with SOAP::Lite is this class used directly. Instead, it is designed to be a superclass within more specific implementation classes. The methods provided by SOAP::Server itself are:
β¨ METHODS β¨
π οΈ new(optional key/value pairs)
$server = SOAP::Server->new(%options);
Creates a new object of the class β¨. Various default instance values are set up, and like many of the constructors in this module, most of the class methods described here may be passed in the construction call by giving the name followed by the parameter (or an array reference if there are multiple parameters). Slay.
π― action(optional new value)
$action = $server->action
Retrieves or sets the value of the action attribute on the server object. This attribute is used when mapping the request to an appropriate namespace or routine. For example, the HTTP library sets the attribute to the value of the SOAPAction header when processing of the request begins, so that the find_target method described later may retrieve the value to match it against the server's configuration. Returns the object itself when setting the attribute. cute.
π¦ myuri(optional new value)
$server->myuri("http://localhost:9000/SOAP");
Gets or sets the myuri attribute. This specifies the specific URI that the server is answering requests to (which may be different from the value specified in action or in the SOAPAction header). iykyk.
π serializer(optional new value) / deserializer(optional new value)
$serializer = $server->serializer;
$server->deserializer($new_deser_obj);
As with the client objects, these methods provide direct access to the serialization and deserialization objects the server object uses to transform input and output from and to XML. There is generally little or no need to explicitly set these to new values. lowkey leave them alone unless you know what you're doing π .
βοΈ options(optional new value)
$server->options({compress_threshold => 10000});
Sets (or retrieves) the current server options as a hash-table reference. At present, only one option is used within the SOAP::Lite libraries themselves:
compress_thresholdβ the value of this option is expected to be a numerical value. If set, and if theCompress::Zliblibrary is available to use, messages whose size in bytes exceeds this value are compressed for transmission. Both ends of the conversation have to support this and have it enabled. no cap.
Other options may be defined and passed around using this mechanism. Note that setting the options using this accessor requires a full hash reference be passed. To set just one or a few values, retrieve the current reference value and use it to set the key(s). periodt.
πΊοΈ dispatch_with(optional new value)
$server->dispatch_with($new_table);
Represents one of two ways in which a SOAP::Server (or derived) object may specify mappings of incoming requests to server-side subroutines or namespaces. The value of the attribute is a hash-table reference. To set the attribute, you must pass a new hash reference. The hash table's keys are URI strings (literal URIs or the potential values of the SOAPAction header), and the corresponding values are one of a class name or an object reference. Requests that come in for a URI found in the table are routed to the specified class or through the specified object. iconic routing behavior, honestly.
π§ dispatch_to(optional list of new values)
$server->dispatch_to($dir, 'Module', 'Mod::meth');
This is the more traditional way to specify modules and packages for routing requests. This is also an accessor, but it returns a list of values when called with no arguments (rather than a single one). Each item in the list of values passed to this method is expected to be one of four things:
- Directory path β if the value is a directory path, all modules located in that path are available for remote use.
- Package name β when the value is a package name (without including a specific method name), all routines within the package are available remotely.
- Fully qualified method name β alternately, when the value is a package-qualified name of a subroutine or method, that specific routine is made available. This allows the server to make selected methods available without opening the entire package.
- Object reference β if the value is an object reference, the object itself routes the request.
The list of values held by the dispatch_to table are compared only after the URI mapping table from the dispatch_with attribute has been consulted. If the request's URI or SOAPAction header don't map to a specific configuration, the path specified by the action header (or in absence, the URI) is converted to a package name and compared against this set of values. bestie, that's the lookup order, don't forget it π«Ά.
π§Έ objects_by_reference(optional list of new values)
$server->objects_by_reference(qw(My:: Class));
This also returns a list of values when retrieving the current attribute value, as opposed to a single value.
This method doesn't directly specify classes for request routing so much as it modifies the behavior of the routing for the specified classes. The classes that are given as arguments to this method are marked to be treated as producing persistent objects. The client is given an object representation that contains just a handle on a local object with a default persistence of 600 idle seconds. Each operation on the object resets the idle timer to zero. This facility is considered experimental in the current version of SOAP::Lite.
β οΈ Experimental alert: this whole persistent-objects-by-reference situation is experimental in this version. Treat it like a cute little beta feature, not a load-bearing wall π.
A global variable/"constant" allows developers to specify the amount of time an object will be persisted. The default value is 600 idle seconds. This value can be changed using the following code:
$SOAP::Constants::OBJS_BY_REF_KEEPALIVE = 1000;
πͺ on_action(optional new value)
$server->on_action(sub { ...new code });
Gets or sets the reference to a subroutine that is used for executing the on_action hook. Where the client code uses this hook to construct the action-request data (such as for a SOAPAction header), the server uses the on_action hook to do any last-minute tests on the request itself, before it gets routed to a final destination. When called, the hook routine is passed three arguments:
actionβ the action URI itself, retrieved from theactionmethod described earlier.method_uriβ the URI of the XML namespace the method name is labeled with.method_nameβ the name of the method being called by the request.
π¬ on_dispatch(optional new value)
($uri, $name) = $server->on_dispatch->($request);
Gets or sets the subroutine reference used for the on_dispatch hook. This hook is called at the start of the request-routing phase and is given a single argument when called:
requestβ an object of theSOAP::SOMclass, containing the deserialized request from the client.
π find_target
($class, $uri, $name) = $server->find_target($req)
Taking as its argument an object of the SOAP::SOM class that contains the deserialized request, this method returns a three-element list describing the method that is to be called. The elements are:
classβ the class into which the method call should be made. This may come back as either a string or an objectreference, if the dispatching is configured using an object instance.uriβ the URN associated with the request method. This is the value that was used when configuring the method routing on the server object.nameβ the name of the method to call.
π¦ handle
$server->handle($request_text);
Implements the main functionality of the serving process, in which the server takes an incoming request and dispatches it to the correct server-side subroutine. The parameter taken as input is either plain XML or MIME-encoded content (if MIME-encoding support is enabled). main character energy fr fr.
π₯ make_fault
return $server->makefault($code, $message);
Creates a SOAP::Fault object from the data passed in. The order of arguments is: code, message, detail, actor. The first two are required (because they must be present in all faults), but the last two may be omitted unless needed.
π§ SOAP::Server::Parameters
This class provides two methods, but the primary purpose from the developer's point of view is to allow classes that a SOAP server exposes to inherit from it. When a class inherits from the SOAP::Server::Parameters class, the list of parameters passed to a called method includes the deserialized request in the form of a SOAP::SOM object. This parameter is passed at the end of the arguments list, giving methods the option of ignoring it unless it is needed. obsessed with the convenience honestly π.
The class provides two subroutines (not methods), for retrieving parameters from the SOAP::SOM object. These are designed to be called without an object reference in the parameter list, but with an array reference instead (as the first parameter). The remainder of the arguments list is expected to be the list from the method-call itself, including the SOAP::SOM object at the end of the list. The routines may be useful to understand if an application wishes to subclass SOAP::Server::Parameters and inherit from the new class instead.
π byNameOrOrder(order, parameter list, envelope)
@args = SOAP::Server::Parameters::byNameOrOrder ([qw(a b)], @_);
Using the list of argument names passed in the initial argument as an array reference, this routine returns a list of the parameter values for the parameters matching those names, in that order. If none of the names given in the initial array-reference exist in the parameter list, the values are returned in the order in which they already appear within the list of parameters. In this case, the number of returned values may differ from the length of the requested-parameters list. the way that works is actually so clever π .
π byName(order, parameter list, envelope)
@args = SOAP::Server::Parameters::byName ([qw(a b c)], @_);
- the sibling accessor β acts in a similar manner to the previous one, with the difference that it always returns as many values as you asked for, even if some (or literally all) of them don't exist π. Parameters that aren't in the parameter list come back as
undefvalues β no errors, no drama, justundefwhere a value would've been. Lowkey the most chill behaviour ever.
π EXAMPLE π
Okay bestie, here's the moment you've been waiting for π. The following is an example CGI based Web Service that utilizes a Perl module which inherits from the SOAP::Server::Parameters class. The way that this lets the methods of that class access their input by name? Iconic. Chef's kiss. Obsessed. β¨
#!/usr/bin/perl
use SOAP::Transport::HTTP;
SOAP::Transport::HTTP::CGI
->dispatch_to('C2FService')
->handle;
BEGIN {
package C2FService;
use vars qw(@ISA);
@ISA = qw(Exporter SOAP::Server::Parameters);
use SOAP::Lite;
sub c2f {
my $self = shift;
my $envelope = pop;
my $temp = $envelope->dataof("//c2f/temperature");
return SOAP::Data->name('convertedTemp' => (((9/5)*($temp->value)) + 32));
}
}
Like, it pops the envelope, grabs the temperature node by name, converts it, and hands back a convertedTemp β that's it, that's the whole vibe π₯. Copy it exactly, character for character, no cap.
π SEE ALSO π
Go read these next, fr fr π«Ά:
SOAP::SOMSOAP::Transport::HTTP
π ACKNOWLEDGEMENTS π
Special thanks to O'Reilly publishing, which has graciously allowed SOAP::Lite to republish and redistribute large excerpts from Programming Web Services with Perl β mainly the SOAP::Lite reference found in Appendix B. Genuinely so generous of them, we stan ππ
Β©οΈ COPYRIGHT Β©οΈ
Copyright (C) 2000-2004 Paul Kulchenko. All rights reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Slay, open source π¦
π AUTHORS π
- Paul Kulchenko (
paulclinger@yahoo.com) - Randy J. Ray (
rjray@blackperl.com) - Byrne Reese (
byrne@majordojo.com)
Three absolute main characters, honestly πβ
That's the whole page bestie β you made it to the end π Go forth and SOAP responsibly π
Peace out from the SOAP::Server(3) girlies π β this was perl v5.42.0, dated 2024-03-04, and yes, we're citing our sources like the academic icons we are πβ¨
π¦ where this page comes from
- opensuse-leap 16.0: perl-SOAP-Lite 1.27-bp160.1.11 Β· (Artistic-1.0 OR GPL-1.0-or-later) AND CC-BY-ND-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms