When I tried to use the DOM parse to read the String returned from getValue it errors out. When I print the string out it is only the value of the "do_testResult", this is the one piece of data this test method returns (it adds two numbers). I have set up the deserializer (using StringDeserializer) for this one result manually since I must since I'm using a .NET server and an Apache Java client. How can I just get the XML returned so I can use this string to create the DOM document? Also, When I use a method that returns more complex XML, do I still need to specify the deserializers for each piece of data returned? I would like to avoid this but my current approach, setting a deserializer for each result returned, would require a deserializer be setup or Apache will complain. Is there anyway to just get the XML as a string and not worry about deserializing. I can do that when I read the values from the XML DOM doc. Any help would be appreciated. here is my client. ************************************************************ package com.telemetrytech.utils; /** * SoapAddTest.java * A class to use the SOAP method test_AddThem on the VNOC server * via Java. This method takes two numbers and returns the result of adding * the two together. * @author Peter Roth (c) Telemetry Technologies 2001 */ import java.io.*; import java.net.*; import java.util.*; import org.apache.soap.*; import org.apache.soap.rpc.*; import org.apache.soap.util.xml.*; import org.apache.soap.encoding.*; import org.apache.soap.encoding.soapenc.*; import org.apache.soap.transport.http.SOAPHTTPConnection; import org.apache.xerces.parsers.DOMParser; import org.xml.sax.InputSource; import java.io.StringReader; public class SoapAddTest { public static void main(String args[]) { //Read in the arguments to add if(args.length < 2) { System.err.println("USAGE java SoapAddTest firstNum secondNum"); return; } Integer firstNum = new Integer (5); Integer secondNum = new Integer(10); try { firstNum = new Integer (args[0]); secondNum = new Integer(args[1]); }catch(NumberFormatException e) { System.out.println("Number Format Exception\n"); e.printStackTrace(); return; } //now lets try and run the method on the server try { //the url of the web service URL url = new URL ("http://63.75.212.15:80/VnocngWebService/VnocngWebService.asmx"); //use this localhost URL when using the TcpTunnelGui java program. //URL url = new URL ("http://localhost:8080/VnocngWebService/VnocngWebService.asmx?wsdl"); SOAPHTTPConnection st = new SOAPHTTPConnection(); //set up the call Call call = new Call(); call.setSOAPTransport(st); call.setTargetObjectURI("http://telemetrytech.net/VnocngWebService"); //call.setTargetObjectURI(""); //same as not including this line call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC); //call.setEncodingStyleURI("http://schemas.xmlsoap.org/soap/encoding/"); //Add the type mapping to the registry SOAPMappingRegistry smr = new SOAPMappingRegistry(); StringDeserializer intDeSer= new StringDeserializer(); // Map the types since xsi:type is not returned with elements from a MS SOAP service. smr.mapTypes(Constants.NS_URI_SOAP_ENC, //new QName("http://telemetrytech.net/VnocngWebService", "vnoc_doSOAPTestResult"), new QName("http://telemetrytech.net/VnocngWebService", "vnoc_doSOAPTestResponse"), null, null, intDeSer); call.setSOAPMappingRegistry(smr); //set up the parameters to the method Vector params = new Vector (); params.addElement (new Parameter("ns1:First_Integer", Integer.class, firstNum, null)); params.addElement (new Parameter("ns1:Second_Integer", Integer.class, secondNum, null)); call.setParams (params); //System.err.println("ENVELOPE:\n\n"+call.toString()+"\n"); //set the method name call.setMethodName ("vnoc_doSOAPTest"); //connect to the web service and run the method getting the response back Response resp = call.invoke(url,"http://telemetrytech.net/VnocngWebService/vnoc_doSOAPTest" ); if (resp.generatedFault ()) { Fault fault = resp.getFault (); System.out.println ("Ouch, 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("\n"+resp.toString()+"\n"); System.out.println("result of "+ firstNum+ " + "+ secondNum+" = "+ result.getValue().toString() ); */ //now try to use the string as an XML doc String xmlString = (String)result.getValue(); System.out.println("XML Doc:\n"+xmlString); DOMParser parser = new DOMParser(); //parser.parse(new InputSource(new StringReader(xmlString))); //Create the DOM from the XML } }catch(MalformedURLException e) { System.out.println("error in URL creation.\n"+e.getMessage()+"\n"); e.printStackTrace(); return; }catch(SOAPException e) { System.out.println("SOAPException\n"); e.printStackTrace(); return; }catch(IOException e) { System.out.println("\nIOException, error processing XML."); e.printStackTrace(); return; }catch(Exception e) { System.out.println("error in call creation.\n"+e.getMessage()+"\n"); e.printStackTrace(); return; } } } ************************************************************ Peter Roth Telemetry Technologies Inc. p: 404.231.0021 ext. 1290 e: [EMAIL PROTECTED] -----Original Message----- From: Pete Roth [mailto:[EMAIL PROTECTED]] Sent: Tuesday, July 31, 2001 2:41 PM To: '[EMAIL PROTECTED]' Subject: RE: Using Xerces to parse a SOAP response and using reflection to abstractly refer to a web service Thanks for your help Steve and Doug. This you guys have solved my problem I think, I'm about to try it. The real question I guess I was asking is in regards to line Doug suggested. myparser.parse((String)ret.getValue()); This String that you cast from the Object returned from getValue(), is this the entire XML response? The apache docs don't really say what this object would be. When I used a SOAP method on the server that only returned one piece of data, I just used "ret.getValue()" to get the value. Now I'm parsing the data returned from a much more complex method and I wanted to use a DOM parser, or something accomplishing the same job of preserving the data hierarchy. I believe what you suggested will do this now. Thank you for the help from both of you. One more question. Is there a way to build a Java class from this XML data? Then I could have a dynamically created class with accessors to get each piece of data from the XML document originally returned. Using reflection classes I could then determine the data returned. I wish to do this because in the future, the data returned from some method could change and I don't want to hard-code the names of the XML nodes and attributes I'm reading from the SOAP response. Eventually, maybe I could even have the WebService return a Java class, in bytecode, with all the methods on the webservice. So that the client could dynamically discover the methods available on the SOAP service. Anyone have any thoughts on doing this? Peter Roth Telemetry Technologies Inc. p: 404.231.0021 ext. 1290 e: [EMAIL PROTECTED] -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] Sent: Tuesday, July 31, 2001 1:51 PM To: [EMAIL PROTECTED] Cc: Soap-dev List (E-mail); Soap-user list (E-mail) Subject: Re: Using Xerces to parse a SOAP response Peter, You mentioned returning a String...is your string an xml doc?(if not it could be...) you can do the following from receiving a Soap call if you know that your method invoked returns a string such as "<a xmlns ="yournamespace"><b>12</b><c>56</c></a>" try { resp = call.invoke(url,"http://tempuri.org/action/youraction"); } catch (SOAPException e) { System.err.println("Caught SOAPException (" + e.getFaultCode() + "): " + e.getMessage()); return; } // Check the response. if (!resp.generatedFault()) { Parameter ret = resp.getReturnValue(); DOMParser myparser = new DOMParser(); myparser.parse((String)ret.getValue()); Document doc = myparser.getDocument(); //now you can do whatever you want with your dom document....although you may want to try a SAX parser as it will be faster and you can create your java objects without having the overhead of the DOM. } else { Fault fault = resp.getFault(); System.err.println("Generated fault: "); System.out.println (" Fault Code = " + fault.getFaultCode()); System.out.println (" Fault String = " + fault.getFaultString()); } etc... hth Doug