ya he construido todo y el web service me regresa la respuesta de lo que envio
el problema es que no puedo obtener el valor de regreso la respuesta del web service es la siguiente
Código PHP:
RESPONSE:
<?xml version="1.0" encoding="UTF-8"?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><ns2:consultaSaldoResponse xmlns:ns2="http://operaciones/"><return>00000000010000</return></ns2:consultaSaldoResponse></S:Body></S:Envelope>
Código PHP:
[Ljava.lang.StackTraceElement;@a0dcd9no protocol: <?xml version="1.0" encoding="UTF-8"?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><ns2:consultaSaldoResponse xmlns:ns2="http://operaciones/"><return>00000000010000</return></ns2:consultaSaldoResponse></S:Body></S:Envelope>
D:
BUILD SUCCESSFUL (total time: 0 seconds)
Código PHP:
package pruebaws;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import org.w3c.dom.*;
public class ReadResponseSaldo {
private String xmlContRes = "";
private String salRes = "";
public ReadResponseSaldo (String xmlR) {
xmlContRes = xmlR;
}
public String getSaldoResponse () {
try {
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
System.out.println(xmlContRes);
System.out.println("entro aqui para ver si pasa");
docBuilderFactory.setValidating(true); // Validamos la estructura del archivo xml
Document doc = docBuilder.parse(xmlContRes);
doc.getDocumentElement().normalize();
String valor;
// valor = doc.getElementsByTagName("S:Envelope").item(0).getTextContent();
System.out.println("llego al valor del s:envelope");
// System.out.println("valor"+ valor);
if (doc.getDocumentElement().getNodeName().equals("S:Envelope"))
{
NodeList listBody = doc.getElementsByTagName("S:Body");
if (listBody.getLength() > 0) {
Node saldoResponse = listBody.item(0);
System.out.println();
salRes = saldoResponse.getTextContent().trim();
}
}
// salRes = valor;
} catch (Exception err) {
System.out.print(err.getStackTrace());
System.out.println(err.getMessage());
}
return salRes;
}
}
Código PHP:
package pruebaws;
import javax.xml.soap.SOAPConnectionFactory;
import javax.xml.soap.SOAPConnection;
import javax.xml.soap.MessageFactory;
import javax.xml.soap.SOAPMessage;
import javax.xml.soap.SOAPPart;
import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPBody;
import java.io.ByteArrayInputStream;
import java.io.OutputStreamWriter;
import java.io.StringReader;
import javax.xml.transform.stream.StreamSource;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamResult;
import java.io.File;
import java.io.StringWriter;
import java.io.Writer;
import java.io.StringReader;
import java.io.Reader;
public class Main {
public static void main(String args[]) {
try {
String df = "<?xml version="1.0\" encoding=\"UTF-8\"?>\n"
+"<S:Envelope xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\">\n"
+"\t<S:Header/>\n"
+"\t<S:Body>\n"
+"\t\t<ns2:consultaSaldo xmlns:ns2=\"http://operaciones/\">\n"
+"\t\t\t<no_Tarjeta>"+"Numero_Tarjeta"+"</no_Tarjeta>\n"
+"\t\t</ns2:consultaSaldo>\n"
+"\t</S:Body>\n"
+"</S:Envelope>\n";
//First create the connection
SOAPConnectionFactory soapConnFactory = SOAPConnectionFactory.newInstance();
SOAPConnection connection = soapConnFactory.createConnection();
//Next, create the actual message
MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage message = messageFactory.createMessage();
//Create objects for the message parts
SOAPPart soapPart = message.getSOAPPart();
SOAPEnvelope envelope = soapPart.getEnvelope();
SOAPBody body = envelope.getBody();
StreamSource preppedMsgSrc = new StreamSource(new ByteArrayInputStream(df.getBytes("UTF-8")));
soapPart.setContent(preppedMsgSrc);
message.saveChanges();
//Check the input
System.out.println("\nREQUEST:\n");
message.writeTo(System.out);
System.out.println();
//Send the message and get a reply
String destination = "http://host_destino";
SOAPMessage reply = connection.call(message, destination);
//Check the output
System.out.println("\nRESPONSE:\n");
//Create the transformer
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
Source sourceContent = reply.getSOAPPart().getContent();
Writer sw = new StringWriter();
StreamResult result = new StreamResult(sw);
transformer.transform(sourceContent, result);
ReadResponseSaldo rs = new ReadResponseSaldo(sw.toString());
System.out.println("D: " + rs.getSaldoResponse());
//System.out.println( rs.getSaldoResponse());
// System.out.println(result.toString());
//Set the output for the transformation
// StreamResult result = new StreamResult(System.out);
//transformer.transform(sourceContent, result);
//System.out.println();
//Close the connection
connection.close();
} catch(Exception e) {
System.out.println(e.getMessage());
}
}
}
espero puedan ayudarme me encuentro en una incrusijada muy fuerte y necesito resolver esto de urgencia, espero su ayuda gracias