Visualizzazione dei risultati da 1 a 8 su 8
  1. #1

    Risposta di un web service

    Ciao a tutti, sto facendo un applicazione che utilizza un web services, una volta fatta la "chiamata" al ws ottengo questa risposta:

    codice:
    <?xml version="1.0" encoding="UTF-8"?>
    	<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:xmethods-delayed-sms" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/			XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
    
    <SOAP-ENV:Body> 
    	<ns1:sendSmsResponse>
    		<Result xsi:type="xsd:string">0</Result>
    	</ns1:sendSmsResponse>
    </SOAP-ENV:Body>
    
    
    </SOAP-ENV:Envelope>
    Ora come faccio a salvarmi il tipo di risposta? qualcuno che mi può dare qualche dritta?

  2. #2
    Utente di HTML.it
    Registrato dal
    Oct 2011
    Messaggi
    147
    Non ho capito cosa ti serve... hai già tutto!! Se hai un Response SOAP Envelope di quel tipo significa che avrai fatto una chiamata del tipo:

    codice:
    oggettoProxy.sendSmsResponse()
    A questo punto:

    codice:
    String risultato = oggettoProxy.sendSmsResponse()
    e il gioco è fatto.

  3. #3
    Io per ottenere questa risposta, utilizzo questo codice (stampo la risposta nella console)

    codice:
             SOAPMessage response = connection.call(message, endpoint);
             
             //Close the connection
             connection.close();
    
             
             System.out.println("SOAP Response Received:");
    
             //Create a transformer
             TransformerFactory tf = TransformerFactory.newInstance();
             Transformer transformer = tf.newTransformer();
             //Retrieve content of the response
             Source content = response.getSOAPPart().getContent();
             
             //Display it on the console
             StreamResult result = new StreamResult(System.out);
             transformer.transform(content, result);
    semplicemente mi serve prendere il valore
    codice:
    <Result xsi:type="xsd:string">0</Result>
    che sta qui dentro..

  4. #4
    Utente di HTML.it
    Registrato dal
    Oct 2011
    Messaggi
    147
    Potresti utilizzare un approccio molto più semplice ed immediato, in ogni caso prova a chiamare getBody() su di un'istanza di SOAPEnvelope.

  5. #5
    codice:
    SOAPBody sb = response.getSOAPBody();
             QName n = sb.getElementQName();
             java.util.Iterator iterator = sb.getChildElements(n);
             while (iterator.hasNext()) {
                 SOAPBodyElement be = (SOAPBodyElement) iterator.next();
                 String val = be.getValue();
                 System.out.println("Valore:" + val);
             }
    ho fatto questo codice, ma nn funziona.. sai per caso dove sbaglio?

  6. #6
    Utente di HTML.it
    Registrato dal
    Oct 2011
    Messaggi
    147
    codice:
    SOAPPart sp = message.getSOAPPart(); 
    SOAPEnvelope se = sp.getEnvelope(); 
    SOAPHeader sh = se.getHeader(); 
    SOAPBody sb = se.getBody();

  7. #7
    ok ho risolto grazie mille

  8. #8
    Utente di HTML.it
    Registrato dal
    Oct 2011
    Messaggi
    147

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2026 vBulletin Solutions, Inc. All rights reserved.