I try to create a Java client for testing at least one web service function
from the WSDL generated by Zend autodiscover. First I'm going to explain how
to reach the point where you can generate a Java client then I'll explain
why I'm blocked and I cannot call the web service function.
***********************************************************
First write the server code is:
***********************************************************
$autodiscover = new Zend_Soap_AutoDiscover();
//the following is important, because Java didn't want to generate if it was
'use' => 'encoded'
$autodiscover->setOperationBodyStyle(
array('use' => 'literal',
'namespace' => $CFG->wwwroot)
);
$autodiscover->setBindingStyle(
array('style' => 'rpc')
);
$autodiscover->setClass('ws_authentication');
$autodiscover->handle();
************************************************************
The loaded class
************************************************************
class ws_authentication {
/**
* Here the function I'm going to call, note that the param is an
associative Array containing string
* @param array|struct $params
* @return integer
*/
function get_token($params) {
if ($params['username'] == 'wsuser' && $params['password'] ==
'wspassword') {
return '456';
} else {
throw new moodle_exception('wrongusernamepassword');
}
}
}
*************************************************************
I can generate some class from Netbeans:
1. Create an empty basic Java project
2. On the project title, right click, select create web service client
3. Choose JAX-RPC style and enter the WSDL address
4. Click on finish, some classes should be generated
5. Insert Code in the Main.java ... call web service operation
At this moment I have the following line:
_ws_authenticationPort.get_token();
I have to pass some params inside the function that are a new java generated
class call Array(), that should contains some sort of SOAPElement. I have no
idea how to create these params. In the PHP server side you can see that is
a associative array.
Were the classes well generated? How to use them ?
Thanks,
Jerome
*************************************************************************************************************************
Following the WSDL (generated by autodiscover) retrieved by the Java client
generator in Netbeans
*************************************************************************************************************************
<?xml version="1.0"?>
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:tns="http://jerome.moodle.com/Moodle_HEAD/moodle/webservice/soap/server.php"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" name="ws_authentication"
targetNamespace="http://jerome.moodle.com/Moodle_HEAD/moodle/webservice/soap/server.php">
<portType name="ws_authenticationPort">
<operation name="get_token">
<input message="tns:get_tokenRequest"/>
<output message="tns:get_tokenResponse"/>
</operation>
</portType>
<binding name="ws_authenticationBinding"
type="tns:ws_authenticationPort">
<soap:binding style="rpc"
transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="get_token">
<soap:operation
soapAction="http://jerome.moodle.com/Moodle_HEAD/moodle/webservice/soap/server.php#get_token"/>
<input>
<soap:body use="literal"
namespace="http://jerome.moodle.com/Moodle_HEAD/moodle"/>
</input>
<output>
<soap:body use="literal"
namespace="http://jerome.moodle.com/Moodle_HEAD/moodle"/>
</output>
</operation>
</binding>
<service name="ws_authenticationService">
<port name="ws_authenticationPort"
binding="tns:ws_authenticationBinding">
<soap:address
location="http://jerome.moodle.com/Moodle_HEAD/moodle/webservice/soap/server.php"/>
</port>
</service>
<message name="get_tokenRequest">
<part name="params" type="soap-enc:Array"/>
</message>
<message name="get_tokenResponse">
<part name="return" type="xsd:int"/>
</message>
</definitions>
--
View this message in context: http://www.nabble.com/-Question--How-to-create-a-Java-client-for-a-Zend_Soap-server-using-autodiscover-functionality-tp23419682p23419682.html
Sent from the Zend Web Services mailing list archive at Nabble.com.
没有评论:
发表评论