Context:
Say I want to pull a list of all objects that exist in the home directory of my SSRS instance. I would look at the server's WSDL (http://location_of_web_service.asmx?WSDL) and find choose the method ListChildren (Side Note: soapUI is an awesome open-source tool for this kind of thing, goolge it).
The WSDL tells us that the 'ListChildren' method takes the parameters 'Item' and 'Recursive.' Item is the folder that you list and Recursive (true/false) is whether or not you want to recursively print the sub-folders. The only way you can figure this out is trial and error, or if you dare, Microsoft documentation.
Parameters:
METHOD: Your SOAP action, example: ListChildren.
PARAMS: Tad trickier. I concatonate the params together then break them apart later due to the fact there may by zero or many. Seperate the parameter name and value with a '$' and multiple name-value pairs with a '^'.
PARAMS example: "parameter1$value1^parameter2$value2"
will yield:
"<namespace:parameter1>value1</namespace:parameter1>
<namespace:parameter2>value2</namespace:parameter2>"
How to use this code:
To use this you will need to set your own envelope_tag and namespace as variables, mine are "rep" and "soap," respectively.
FUNCTION BUILD_ENVELOPE
(
METHOD VARCHAR2
,PARAMS CLOB
) RETURN CLOB
PARALLEL_ENABLE is
ENVELOPE CLOB;
PARAM_SECTION CLOB;
PARAM_REG VARCHAR2(10) := '[^^]+';
VALUE_REG VARCHAR2(10) := '[^$]+';
BEGIN
--Add namespaces to envelope. Add an empty header.
ENVELOPE := '<' || ENVELOPE_TAG || ':Envelope xmlns:' || ENVELOPE_TAG || '="http://schemas.xmlsoap.org/soap/envelope/" '
|| 'xmlns:' || NAMESPACE || '="http://schemas.microsoft.com/sqlserver/2005/06/30/reporting/reportingservices">'
|| '<' || ENVELOPE_TAG || ':Header>'
|| '</' || ENVELOPE_TAG || ':Header>'
|| '<' || ENVELOPE_TAG || ':Body>'
|| '<' || NAMESPACE || ':' || METHOD || '>';
--each method can take zero or many parameters, this function will take a list as "<param1>$<value1>^<param2>$<value2>^..."
IF TRIM(PARAMS) IS NOT NULL
THEN
FOR I IN 1 .. REGEXP_COUNT(PARAMS, PARAM_REG)
LOOP
--Select out the parameter value pair.
PARAM_SECTION := TRIM(REGEXP_SUBSTR(PARAMS, PARAM_REG, 1, I));
IF (PARAM_SECTION) IS NOT NULL
THEN
BEGIN
-- Concatonate the parameter-value pair as <namespace:param>value<namespace:param>
ENVELOPE := ENVELOPE
|| '<' || NAMESPACE || ':' || TRIM(REGEXP_SUBSTR(PARAM_SECTION, VALUE_REG, 1, 1)) || '>'
|| TRIM(REGEXP_SUBSTR(PARAM_SECTION, VALUE_REG, 1, 2))
|| '</' || NAMESPACE || ':' || TRIM(REGEXP_SUBSTR(PARAM_SECTION, VALUE_REG, 1, 1)) || '>';
END;
END IF;
END LOOP;
END IF;
-- Close the envelope
ENVELOPE := ENVELOPE
|| '</' || NAMESPACE || ':' || METHOD || '>'
|| '</' || ENVELOPE_TAG || ':Body>'
|| '</' || ENVELOPE_TAG || ':Envelope>';
RETURN(ENVELOPE);
EXCEPTION
WHEN OTHERS THEN
LOG_TO_TABLE('BUILD_ENVELOPE'
,'Exception thrown on action: ' || METHOD || ', params: ' || PARAMS || ' error: ' || SQLERRM , 'E');
RETURN NULL;
END BUILD_ENVELOPE;
I feel SQL and other aspects really provide more and more information about various aspects to solve complex database IT problems.
ReplyDeleteSQL Server Load Rest Api