Java Reference
In-Depth Information
This code will create an org.w3c.dom.Document object representing an XML tree. You can now
traverse this tree to get out your information. Looking at the result, you can see that stock informa-
tion is provided in “Stock” tags, with each piece of information being stored in a separate subtag. So
modify your method once again, so that the complete class will look like this:
import java.io.StringReader;
import javax.xml.namespace.QName;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.soap.MessageFactory;
import javax.xml.soap.MimeHeaders;
import javax.xml.soap.SOAPBody;
import javax.xml.soap.SOAPBodyElement;
import javax.xml.soap.SOAPConnection;
import javax.xml.soap.SOAPConnectionFactory;
import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPMessage;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
public class ClientWithoutWSDL {
private final static String SERVICE_HOST = " http://www.webserviceX.NET/";
private final static String SERVICE_METHOD = "GetQuote";
private final static String SERVICE_ENDPOINT = "stockquote.asmx";
private final static String STOCK_SYMBOL = "IBM";
public static void main(String args[]) {
try {
// Create a new SOAP connection
SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory
.newInstance();
SOAPConnection soapConnection = soapConnectionFactory
.createConnection();
// Send a SOAP Message to SOAP server
// Send this message to http://www.webserviceX.NET/stockquote.asmx
SOAPMessage soapResponse = soapConnection.call(
createSOAPRequest(STOCK_SYMBOL), SERVICE_HOST
+ SERVICE_ENDPOINT);
showSOAPResponse(soapResponse);
// Close the connection
soapConnection.close();
} catch (Exception e) {
System.err.println("Fatal error occurred");
e.printStackTrace();
}
Search WWH ::




Custom Search