Ver Mensaje Individual
  #1 (permalink)  
Antiguo 12/12/2007, 10:09
tucome
 
Fecha de Ingreso: junio-2007
Mensajes: 46
Antigüedad: 16 años, 11 meses
Puntos: 0
Recibir xml en servicio web

Hola estoy haciendo un servicio web con NetBeans y al enviar un xml al servicio web éste no me lo reconoce como un String, haber si alguien me puede ayudar, ahí pongo el código que tengo hecho hasta ahora.


Cita:
public static void main(String[] args) {
String xmlString = "<a>SEVILLA</a>";

try{
String serv=
"<Cuadrado xmlns=\"http://tmp/\">" +
"<entrada xmlns=\"\">" + xmlString +
"</entrada>" +
"</Cuadrado>";
String rutaServicio = "http://localhost:8084/EjemploWeb3/Servicio";
String uri = "http://tmp";

String resultado = webServCall(serv,rutaServicio,uri);
System.out.println(resultado);
} catch (Exception ex){
System.out.println("Error producido en llamada a Servicio web: "+ ex.getMessage());
}
}
El webServCall es donde monto mi mensaje Soap y es el siguiente:

Cita:
public static String webServCall(String param, String rutaServicio, String uri) throws Exception {
Document doc = null;
Element personal = null;

String resultado="";
try{
DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBu ilder();

StringReader reader = new StringReader(param);
InputSource source = new InputSource(reader);
doc = docBuilder.parse(source);
if(doc==null){
throw new org.apache.soap.SOAPException(org.apache.soap.Cons tants.FAULT_CODE_CLIENT,"Error en parseo");
}
//CONSTRUIR MENSAJE EN SOAP
org.apache.soap.Envelope envelope = new org.apache.soap.Envelope();
Vector bodyElements = new Vector();
bodyElements.add(doc.getDocumentElement());
org.apache.soap.Body body = new org.apache.soap.Body();
body.setBodyEntries(bodyElements);
envelope.setBody(body);

//ENVIAMOS MENSAJE
org.apache.soap.messaging.Message msg = new org.apache.soap.messaging.Message();
msg.send(new java.net.URL(rutaServicio),uri,envelope);


org.apache.soap.transport.SOAPTransport st = msg.getSOAPTransport();
BufferedReader br = st.receive();
String line = br.readLine();
if(line==null)
throw new Exception("SOAP ERROR");
else{
while(line!=null) {
resultado += line;
line = br.readLine();
}
}
} catch (Exception e){throw e;}

return resultado;
}

}

Y la función en el Servicio web es la siguiente:

Cita:
@WebService()
public class Servicio {
public String Cuadrado(@WebParam (name = "entrada") String entrada) throws Exception {

return entrada;
}
}

Como se ve el ejemplo que estoy haciendo es bastante sencillo solo quiero que me muestre por pantalla lo que le introduzco a la función pero ésta nunca me devuelve nada.

Muchas gracias