CA Service Management

 View Only

SPEL: How to call SDM method using WebServies 

Apr 07, 2016 11:20 AM

Introducing short guide with information consolidated from this community

 

     Register new method

To register new method new maj file should be created within /site/mods/majic folder, in my example I used api factory without any reason, you can use any factory you want.

Please notice: logged user should have rights to modify objects in selected factory.

// FILENAME: z_api.maj
OBJECT api {
    FACTORY {
        METHODS {
            z_echo(...);
        };
    };
};

Method is called z_echo, there is no input arguments specified, ellipsis means that it could receive any amount of attributes.

 

     Create spel file to execute method

I have used very simple spel which is used to return input attributes back as response.

// FILENAME: z_api.spl
api::z_echo(...) {
    int i;
    for (i=0;i<argc;i++) {
        set_return_data(i, argv[i]);
    }
}

File should be located in same folder as maj.

 

     Call method using WebServies

For test purposes I have used SoapUI software which is free and open source, could be downloaded here: SoapUI | Functional Testing for SOAP and REST APIs

Method call:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://www.ca.com/UnicenterServicePlus/ServiceDesk">
   <soapenv:Header/>
   <soapenv:Body>
      <ser:callServerMethod>
         <sid>1141608663</sid>
         <methodName>z_echo</methodName>
         <factoryName>api</factoryName>
         <formatList></formatList>
         <parameters>
            <string>Hello</string>
            <string>World</string>
   <string>!!!</string>
         </parameters>
      </ser:callServerMethod>
   </soapenv:Body>
</soapenv:Envelope>

 

Method response:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soapenv:Body>
      <callServerMethodResponse xmlns="http://www.ca.com/UnicenterServicePlus/ServiceDesk">
         <callServerMethodReturn xmlns=""><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
<ServerReturn>
<Param0>Hello</Param0>
<Param1>World</Param1>
<Param2>!!!</Param2>
</ServerReturn>]]></callServerMethodReturn>
      </callServerMethodResponse>
   </soapenv:Body>
</soapenv:Envelope>

 

     Information used

Many thanks to Gutis who provided this useful doc: SPEL API methods

And shared how to return multiple attributes from method: Re: Spel to get array from function

Statistics
0 Favorited
36 Views
0 Files
0 Shares
0 Downloads

Tags and Keywords

Comments

Sep 13, 2019 12:54 PM

Using 'spell_object' to return values.

void z_spell_object(...)
{
	int zi_i;
	
	send_wait(0, spell_object(),	// @|bop_cmd-#8184|doit|0|0
			"zGetArray",	// method name
			(string)NULL,	// class name (same as class() ?)
			(string)NULL,	// event or macro name (same as event() ?)
			(object)NULL,	// "this" pointer of type object
			'input0',	// input arguments
			'input1',
			'input2'
			);

	for (zi_i=0;zi_i<msg_length();zi_i++) {
		printf("#%d: '%s'\n", zi_i, (string) msg[zi_i]);
	}

}

void zGetArray(...)
{
	int zi_i;
	// Returns 'inputs'
	for (zi_i=0;zi_i<argc;zi_i++) {
		set_return_data(zi_i, argv[zi_i]);
	}

	// Returns 'outputs'
	for (zi_i=zi_i;zi_i<argc*2;zi_i++) {
		set_return_data(zi_i, format("output%d", zi_i));
	}
}

Returns:
#0: 'input0'
#1: 'input1'
#2: 'input2'
#3: 'output3'
#4: 'output4'
#5: 'output5'

Oct 03, 2017 09:02 AM

It really works. Thank you very much.

May 20, 2016 02:51 PM

This is very nice!!

Thanks for sharing!!!

 

Apr 08, 2016 06:00 AM

Always great to see people sharing with the communities.

Great job cdtj  and Gutis !!

 

/J

Apr 07, 2016 09:16 PM

A gold star and a koala stamp for this one!  There are endless possibilities for this, many thanks for sharing this gem.

Regards,

James

Apr 07, 2016 05:06 PM

This is awesome. It was on my Todo list,  and you saved me a lot of time. Thanks Timur.

Related Entries and Links

No Related Resource entered.