Bonjour
je bloque avec Soap pour récupérer une array.
Mon serveur est en Php il renvoie une array ,il fonctionne bien avec un client php mais en testant avec un client java il bloque voila le code :
client java
le fichier WSDL
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
78
79 package onjava; import java.io.*; import java.lang.reflect.Array; import java.net.*; import java.util.*; import javax.xml.rpc.encoding.XMLType; import org.apache.soap.*; import org.apache.soap.encoding.SOAPMappingRegistry; import org.apache.soap.encoding.soapenc.ArraySerializer; import org.apache.soap.encoding.soapenc.Base64; import org.apache.soap.encoding.soapenc.BeanSerializer; import org.apache.soap.encoding.soapenc.DateSerializer; import org.apache.soap.encoding.soapenc.DoubleDeserializer; import org.apache.soap.encoding.soapenc.DoubleObjectDeserializer; import org.apache.soap.encoding.soapenc.IntDeserializer; import org.apache.soap.encoding.soapenc.LongDeserializer; import org.apache.soap.encoding.soapenc.MapSerializer; import org.apache.soap.encoding.soapenc.StringDeserializer; import org.apache.soap.encoding.soapenc.UrTypeDeserializer; import org.apache.soap.encoding.soapenc.VectorSerializer; import org.apache.soap.rpc.*; import org.apache.soap.util.xml.Deserializer; import org.apache.soap.util.xml.QName; public class CalcClient { public static void main(String[] args) throws Exception { URL url = new URL ("http://localhost/soap/server/index.php"); // Creation de l'appel Call call = new Call(); call.setTargetObjectURI("urn:WebServiceFirst"); call.setMethodName("getHelloWorld"); call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC); //serialistation du type de retour SOAPMappingRegistry soapMappingRegistry = new SOAPMappingRegistry(); BeanSerializer beanSer = new BeanSerializer(); soapMappingRegistry.mapTypes(Constants.NS_URI_SOAP_ENC, new QName("", "value"),CalcClient.class, beanSer, beanSer); call.setSOAPMappingRegistry(soapMappingRegistry); // make the call: note that the action URI is empty because the // XML-SOAP rpc router does not need this. This may change in the // future. Response resp = call.invoke(url, "" ); // verifier la réponse. if ( resp.generatedFault() ) { Fault fault = resp.getFault (); System.out.println("The call failed: "); System.out.println("Fault Code = " + fault.getFaultCode()); System.out.println("Fault String = " + fault.getFaultString()); } else { Parameter result = resp.getReturnValue(); System.out.println(result.getValue().toString()); System.out.println("The call succes "+result.toString()); } } }
mon serveur PHP
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 <?xml version="1.0"?> <definitions name="CSP" targetNamespace="urn:CSP" xmlns:tns="urn:CSP" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:typens="urn:CSP" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/"> <wsdl:types><xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:CSP"> <xsd:complexType name="MyResults"> <xsd:sequence> <xsd:element name="date" type="xsd:string"></xsd:element> </xsd:sequence> </xsd:complexType></xsd:schema></wsdl:types> <message name="getHelloWorld"> <part name="none" type="xsd:int"/> </message> <message name="getHelloWorldResponse"> <part name="value" type="tns:MyResults"/> </message> <portType name="CspPorts"> <operation name="getHelloWorld"> <input message="typens:getHelloWorld"/> <output message="typens:getHelloWorldResponse"/> </operation> </portType> <binding name="MyBinding" type="tns:CspPorts"> <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" /> <operation name="getHelloWorld"> <soap:operation soapAction="http://127.0.0.1/soap/server/server.wsdl" /> <input> <soap:body use="literal" /> </input> <output> <soap:body use="literal" /> </output> </operation> </binding> <service name="WebServiceFirst"> <documentation>Web Service First</documentation> <port name="CspPorts" binding="typens:MyBinding"> <soap:address location="http://127.0.0.1/soap/server/"/> </port> </service> </definitions>
en fin la fonction appelé
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 <?php // On désactive la mise en cache du wsdl (pour le test) ini_set('soap.wsdl_cache_enabled', 0); // Inclusion de la classe contenant l'implémentation des fonctions du Service Web include('WebServiceFirst.php'); // Tentative d'instanciation du serveur SOAP try { $server = new SoapServer('server.wsdl', array('trace' => 1, 'soap_version' => SOAP_1_1)); $server -> setclass('WebServiceFirst'); } catch (Exception $e) { //TODO Traitement en cas d'exception, pour l'instant on l'affiche tel quel... echo $e; exit(); } // Appel du Service Web (requête POST uniquement autorisée) if ($_SERVER['REQUEST_METHOD'] == 'POST') { // Prise en charge de la requête $server -> handle(); } // Sinon, on affiche la liste des fonctions du serveur SOAP et un lien vers le WSDL else { echo 'Web Service First.<br />'; echo '<a href="server.wsdl">WSDL</a><br />'; echo 'Fonctions :'; echo '<ul>'; foreach($server -> getFunctions() as $func) { echo '<li>' , $func , '</li>'; } echo '</ul>'; } ?>
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 <?php class WebServiceFirst { /** * Retourne la chaine 'Hello World' * * @access public * @return string */ public function getHelloWorld() { return array('date' => "bonjour"); } } ?>
l'erreur coté éclipse :
Exception in thread "main" [SOAPException: faultCode=SOAP-ENV:Client; msg=No Deserializer found to deserialize a ':date' using encoding style 'http://schemas.xmlsoap.org/soap/encoding/'.; targetException=java.lang.IllegalArgumentException: No Deserializer found to deserialize a ':date' using encoding style 'http://schemas.xmlsoap.org/soap/encoding/'.]
at org.apache.soap.rpc.Call.invoke(Call.java:246)
at onjava.CalcClient.main(CalcClient.java:59)
j'ai essayé d'ajouter cette ligne mai rien a faire
merci de votre aide; je galère depuis des jours.soapMappingRegistry.mapTypes(Constants.NS_URI_SOAP_ENC, new QName("", "date"),CalcClient.class, null, new StringDeserializer());
Partager