simple PHP example?

User 74d30c678b

18-08-2009 14:49:35

Dear support,


I am trying to access the MolConvertWS through PHP. A simple sample script would be tremendously helpful. I would like to convert a SMILES to an image and display this. Something along these lines (it is not working):


<?php
$client = new SoapClient('http://xxx:xxx/axis2/services/MolConvertWS?wsdl');
?>
<html>
<body>
SOAP TEST PAGE<BR>
<?php
$image = $client->convert('CCCC', 'png');
?>
<img src="<?php echo $image;?>">
</body>
</html>

A quick and dirty demo php would be usefull to the entire community.


Thanks and best regards,


Daniel

ChemAxon ebbce65bcf

19-08-2009 10:27:41

Hi Daniel,


Using the PHP SoapClient you should add two things to your example, as I see. First you need to specify the parameters of the web service method (like 'targetStructure' and 'outputFormat' for method 'convert'). In addition you should tell the browser that it has to process a directly given base64 encoded image instead of an url. To accomplish this, insert 'data:image/png;base64,' string into the <img> source just before the binary data the web service returns. Here is the modified code which successfully generates an image, I hope it helps.


<html>
<head>
 <title>Image generation example</title>
</head>
<body>
<?php
$soap = new SoapClient('http://localhost:8180/axis2/services/MolConvertWS?wsdl');
$return = $soap->convert(array('targetStructure' => 'CCCC', 'outputFormat' => 'png'));
$format = 'png';
echo '<img src="data:image/'.$format.';base64,'.$return->return.'" alt="molecule" />';
?>
</body>
</html>

Regards,


Roland

User 74d30c678b

25-08-2009 09:33:19

Dear Roland,


Thank you very much, this works perfectly.


Best regards,


Daniel.

User 74d30c678b

28-08-2009 05:48:26

Dear support,


how do I add the export options to outputFormat? When trying to expand the example above, I expected this would work:


$return = $soap->convert(array('targetStructure' => 'CCCC', 'outputFormat' => 'png:w100,h100,H_off')); 

I'll get SOAP errors (cannot export) when using this (5.2.4 Webservices installed).


Any help is appreciated.


Thanks and best regards,


Daniel

User c1ce6b3d19

01-09-2009 13:26:55


Daniel,


Currently, the MolConvertWS does not recognize the colon (':')
additional formatting in output format as needing base64 encoding.  It
tries to return the image in a basic string and will likely fail during
transport.


This will be fixed in the 5.2.5 release. 


 


Jonathan Lee


User e34a92cce5

04-11-2009 03:36:50

Hi,


I am trying to use the following code to run a JChem search using JChemSearchWS. I am using JChem Web services 5.2.6. The code looks like this:


$soap = new SoapClient('http://localhost:8080/axis2/services/JChemSearchWS?wsdl');


$search_param = array(  'connectionHandlerId' => $soap->getConnection($conn_param)->return,
                        'tableName' => 'COMPOUNDS',
                        'queryMolecule' => 'CC(=O)',
                        'queryOptions' => 'sep=! t:s!maxHitCount:0!maxTime:60000!returnNonHits:n!',
                        'beginIndex' => '0',
                        'count' => '4',
                        'outputFormat' => 'smiles',
                        'dataFieldNames' => 'cd_id cd_timestamp'
                    );
$search_result = $soap->runCompleteSearch($search_param);


The error message is


Cannot find connectionHandler ID=<ConnectionHandlerId>connectionHandlerID283142805</ConnectionHandlerId>......


I'd appreciate any help in making this work.

User c1ce6b3d19

04-11-2009 10:57:58

It looks like you need to grab the value, "ConnectionHandlerID283142805" inside of the xml tags. 



<ConnectionHandlerId>connectionHandlerID283142805</ConnectionHandlerId>

User e34a92cce5

04-11-2009 13:16:20

Hi Jon,


I'm not sure what you meant. I am grabbing thevalue within the XML tags by using:



$soap->getConnection($conn_param)->return


When I echo the above code, I get just the connectionID without the XML tags. The SOAP fault code is :


SOAP Fault: (faultcode: soapenv:Server, faultstring: Cannot find connectionHandler ID=ConnectionHandlerID283142805


 

User c1ce6b3d19

04-11-2009 13:28:59

Renju,


We're looking into it currently and will get back to you soon.


Although it sounds like you have it correct, I wanted to clarify my last message. 


I mean that you should strip the ConnectionHandlerId XML tags ("<ConnectionHandlerId>" and "</ConnectionHandlerId>") and just get the string value  starting with "connectionHandlerID".


 


Jon

User e34a92cce5

04-11-2009 13:35:37

I understand now. I modified the code by adding strip_tags and it worked :


$search_param = array(  'connectionHandlerId' => strip_tags($soap->getConnection($conn_param)->return),......
                   



Thanks!