Bonjour,
J'ai récemment créé un web service en PHP, qui tourne bien, je peux l'appeler depuis un script client PHP sans erreur.
Voici le code du fichier 'server.php' (si besoin est) :
L'étape suivante a été de faire un programme Java chargé d'appelé ce web service.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77 <?php // load SOAP library require_once("libs/nusoap.php"); require_once("libs/functions.php"); // load library that holds implementations of functions we're making available to the web service // set namespace $ns="http://127.0.0.1:8989/ws_mvp/test"; // create SOAP server object $server = new soap_server(); // setup WSDL file, a WSDL file can contain multiple services $server->configureWSDL('MvpSystem',$ns); $server->wsdl->schemaTargetNamespace=$ns; // register a web service method function search($query) { $results = array(); $tempArray = array('id' => '1', 'name' => 'MVP2', 'hp' => '15000000' ); array_push($results, $tempArray); $tempArray = array('id' => '2', 'name' => 'MVP1', 'hp' => '3500000' ); array_push($results, $tempArray); return $results; } $server->wsdl->addComplexType('Mvp', 'complexType', 'struct', 'all', '', array( 'id' => array('name' => 'id', 'type' => 'xsd:int'), 'name' => array('name' => 'firstName', 'type' => 'xsd:string'), 'hp' => array('name' => 'lastName', 'type' => 'xsd:int') ) ); $server->wsdl->addComplexType('Mvps', 'complexType', 'array', '', 'SOAP-ENC:Array', array(), array( array('ref'=>'SOAP-ENC:arrayType', 'wsdl:arrayType'=>'tns:Mvp[]') ), 'tns:Mvp' ); $server->register('search', array('query' => 'xsd:string'), array('return' => 'tns:Mvps'), $ns, '$ns#search', 'rpc', 'encoded', 'Returns the data for every person' ); // service the methods $HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : ''; $server->service($HTTP_RAW_POST_DATA); ?>
J'ai donc créé un Main de test dont voici le code :
La classe Bean 'Mvp' contient un constructeur, des getters / setters pour les propriété de classes 'id', 'level', 'name', 'hp', et étends 'Serializable'.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44 public static void main (String[] args){ BasicConfigurator.resetConfiguration(); BasicConfigurator.configure(); String endpoint = "http://127.0.0.1:8989/ws_mvp/test/server.php"; String myOpName = "search"; Service service = new Service(); try{ Call call = ( Call )service.createCall(); call.setTargetEndpointAddress(new java.net.URL(endpoint)); QName qn = new QName("urn:Mvp", "Mvp" ); call.registerTypeMapping( Mvp.class, qn, new BeanSerializerFactory(Mvp.class,qn), new BeanDeserializerFactory(Mvp.class,qn) ); call.setOperationName( new QName( "http://soapinterop.org/", myOpName ) ); call.addParameter("query",XMLType.XSD_STRING, ParameterMode.IN); call.setReturnType(XMLType.SOAP_ARRAY); Object ret = call.invoke( new Object[] { "test" } ); System.out.println("Result = "+ret); }catch(RemoteException e){ System.out.println("Remote error : "+e.getMessage()); }catch(ServiceException e){ System.out.println("Service error : "+e.getMessage()); }catch(MalformedURLException e){ System.out.println("MalformedUrl error : "+e.getMessage()); } }
J'ai l'erreur suivante lorsque j'exécute le Main :
Un peu plus haut dans les logs, j'obtiens également cette erreur:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 1313 [main] DEBUG org.apache.axis.utils.NSStack - NSPush (32) 1313 [main] DEBUG org.apache.axis.encoding.DeserializationContext - Exit: DeserializationContext::startElement() 1313 [main] DEBUG org.apache.axis.encoding.DeserializationContext - Enter: DeserializationContext::startElement(, item) 1313 [main] DEBUG org.apache.axis.encoding.ser.ArrayDeserializer - Enter: ArrayDeserializer.onStartChild() 1313 [main] DEBUG org.apache.axis.encoding.ser.ArrayDeserializer - Exit: ArrayDeserializer.onStartChild() 1313 [main] DEBUG org.apache.axis.i18n.ProjectResourceBundle - org.apache.axis.i18n.resource::handleGetObject(pushHandler00) 1313 [main] DEBUG org.apache.axis.encoding.DeserializationContext - Pushing handler org.apache.axis.encoding.DeserializerImpl@1e1dadb 1313 [main] DEBUG org.apache.axis.i18n.ProjectResourceBundle - org.apache.axis.i18n.resource::handleGetObject(gotType00) 1313 [main] DEBUG org.apache.axis.encoding.DeserializerImpl - Deser got type {http://127.0.0.1:8989/ws_mvp/test}Mvp 1313 [main] DEBUG org.apache.axis.i18n.ProjectResourceBundle - org.apache.axis.i18n.resource::handleGetObject(noDeser00) 1313 [main] DEBUG org.apache.axis.i18n.ProjectResourceBundle - org.apache.axis.i18n.resource::handleGetObject(exception00) 1313 [main] ERROR org.apache.axis.client.Call - Exception: org.xml.sax.SAXException: No deserializer for {http://127.0.0.1:8989/ws_mvp/test}Mvp at org.apache.axis.encoding.DeserializerImpl.onStartElement(DeserializerImpl.java:453) at org.apache.axis.encoding.DeserializerImpl.startElement(DeserializerImpl.java:393) at org.apache.axis.encoding.DeserializationContext.startElement(DeserializationContext.java:1048) at org.apache.axis.message.SAX2EventRecorder.replay(SAX2EventRecorder.java:165) at org.apache.axis.message.MessageElement.publishToHandler(MessageElement.java:1141) at org.apache.axis.message.RPCElement.deserialize(RPCElement.java:236) at org.apache.axis.message.RPCElement.getParams(RPCElement.java:384) at org.apache.axis.client.Call.invoke(Call.java:2467) at org.apache.axis.client.Call.invoke(Call.java:2366) at org.apache.axis.client.Call.invoke(Call.java:1812) at org.kijsoft.mvp.timer.TestWs.main(TestWs.java:56) Remote error : ; nested exception is: org.xml.sax.SAXException: No deserializer for {http://127.0.0.1:8989/ws_mvp/test}Mvp
Est-ce que quelqun aurait une idée qui puisse m'aider à avancer sur ce problème ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5 969 [main] DEBUG org.apache.axis.ConfigurationException - Exception: org.apache.axis.ConfigurationException: No service named http://soapinterop.org/ is available org.apache.axis.ConfigurationException: No service named http://soapinterop.org/ is available at org.apache.axis.configuration.FileProvider.getService(FileProvider.java:233)
Je pense pourtant avoir correctement déclarer ma structure lors de l'appel, mais je me doute qu'il y a un souci quelque part, lequel ?
En vous remerciant d'avance pour le temps que vous prendrez à m'aider.
Cordiale
Partager