IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Services Web Java Discussion :

Probléme: un client java qui consomme une array avec soap


Sujet :

Services Web Java

  1. #1
    Futur Membre du Club
    Inscrit en
    Novembre 2006
    Messages
    8
    Détails du profil
    Informations forums :
    Inscription : Novembre 2006
    Messages : 8
    Points : 8
    Points
    8
    Par défaut Probléme: un client java qui consomme une array avec soap
    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
    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());
        }
      }
    }
    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
    <?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>
    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
    <?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>'; 
    }  
    ?>
    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
    <?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
    soapMappingRegistry.mapTypes(Constants.NS_URI_SOAP_ENC, new QName("", "date"),CalcClient.class, null, new StringDeserializer());
    merci de votre aide; je galère depuis des jours.

  2. #2
    Futur Membre du Club
    Inscrit en
    Novembre 2006
    Messages
    8
    Détails du profil
    Informations forums :
    Inscription : Novembre 2006
    Messages : 8
    Points : 8
    Points
    8
    Par défaut
    Bonjour
    c 'est résolu en générant a partir du WSDL avec Axis 1.4 les classe nécessaire et faire leur classe main

Discussions similaires

  1. Réponses: 17
    Dernier message: 23/09/2010, 17h06
  2. Réponses: 7
    Dernier message: 17/09/2010, 14h57
  3. methode java qui ouvre une navigation vers une url
    Par info_systeme dans le forum Débuter avec Java
    Réponses: 6
    Dernier message: 15/10/2009, 17h47
  4. Réponses: 8
    Dernier message: 17/12/2008, 11h10
  5. [VB6] Problème de textbox multiligne qui génére une erreur
    Par bb62 dans le forum VB 6 et antérieur
    Réponses: 1
    Dernier message: 20/02/2006, 16h21

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo