Java Reference
In-Depth Information
To keep things orderly, you can set up a number of static variables to hold this information, so the
first iteration of the ClientWithoutWSDL class should look like this:
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";
public static void main(String args[]) {
}
}
Take special care to enter these constants exactly as listed in the code snippet. Note that you should
be using http://www.webserviceX.NET/ and not http://www.webservicex.net/ or www
.webservicex.net . These addresses are case sensitive. The reasons for this will become apparent
later on.
Note The Internet is a rapidly changing place, and with a chapter on web ser-
vices, we risk the possibility that websites might no longer work (or have been
changed) by the time you read this chapter. That said, all web resources used
here have been chosen based on the amount of time they have been around
and their maturity (e.g., WebServiceX responds to millions of queries a day).
Keep an eye on the online resources for this topic at www.wrox.com to get
notified in case things break.
Next, you will start creating the actual SOAP request message. To do so, you will use a number of
classes made available under javax.xml.soap :
import javax.xml.soap.SOAPConnection;
import javax.xml.soap.SOAPConnectionFactory;
import javax.xml.soap.SOAPMessage;
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();
Search WWH ::




Custom Search