Forums

Form to send data as SOAP request

JohnDS 10 Sep, 2010
Hi,
I need to send data as a SOAP xml request, I thought I'd be able to add PHP code (on Submit) which would achieve this but it's not been easy to find an example (that works). Any help would be most appreciated, thanks
John
GreyHead 10 Sep, 2010
Hi JohnDS,

I don't remember anyone posting about a SOAP link-up and I know next to nothing about SOAP. I have been successful in using the Joomla! XML-RPC library with ChronoForms though so I guess that it must be possible.

Bob
nml375 10 Sep, 2010
Hi John,
I have used Soap with PHP, though not explicitly with ChronoForms. However, it should'nt be any harder to implement in CF than in simple PHP.

It's fairly trivial using the SoapClient PHP-class, create a new instance of the class pointing to the WSDL-descriptor of the SoapService. Then, you can call any method in the Soap engine as a local class method of the newly created instance:
<?
$mysoap = new SoapClient('http://www.example.com/soap.wsdl');
print_r($mysoap->doExampleTask());
?>

Passing parameter values along with the Soap call is a bit more difficult, as the class-methods only takes one parameter. This should be an array with name=>value pairs of the actual parameters in the Soap interface:
<?
$mysoap = new SoapClient('http://www.example.com/soap.wsdl');
$params = new Array(
  'arg0' => 'A string',
  'arg1' => 123
);
print_r($mysoap->doOtherTask($params));

The exact names for arg0, arg1, and so on can be retrieved from the WSDL-file. Also, keep in mind that the SoapClient class will cache the WSDL by default, so make sure to turn this off if your Soap-API is not finalized yet.

/Fredrik
JohnDS 16 Sep, 2010
Hi,
Thanks for the replies, just to let you know I've found the implementation of SOAP via my service provider a bit problematic so far. I've only been trying to get a simple example working - pretty much the same as Fredrik has explained. The closest I've got was to get the error "The named parameter symbol is not in the call parameters". I've found it really difficult to get an up to date example that works. I'll post up as soon as I get any success.
nml375 16 Sep, 2010
Hi John,
That error usually suggests that the name of one or more of the parameters ('arg0' and 'arg1' in my example) is incorrectly spelled (note that case matters here).

I can't assist much further than that on this error, without the code you use and the WSDL-file.

/Fredrik
cdominguez 08 Nov, 2010
Hi John,

To get the names of one or more parameters in PHP5 you can execute next sentence:
$client->__getTypes();

This returns all parameters and their types that you need when you call to Web Service and what returns you.

Good luck!
This topic is locked and no more replies can be posted.