Java Reference
In-Depth Information
import javax.xml.soap.SOAPConnection;
import javax.xml.soap.SOAPConnectionFactory;
import javax.xml.soap.SOAPElement;
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();
// 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);
System.out.println("Received SOAP reply:");
soapResponse.writeTo(System.out);
System.out.println("\r\n");
// Close the connection
soapConnection.close();
} catch (Exception e) {
System.err.println("Fatal error occurred");
e.printStackTrace();
}
}
private static SOAPMessage createSOAPRequest(String stockSymbol)
throws Exception {
// *UNCHANGED*
}
}
If you run the code again, you'll see:
Sending SOAP request:
<SOAP-ENV:Envelope xmlns:SOAP-ENV=" http://schemas.xmlsoap.org/soap/envelope/" >
<SOAP-ENV:Header/><SOAP-ENV:Body/></SOAP-ENV:Envelope>
Received SOAP reply:
<?xml version="1.0" encoding="utf-8"?><soap:Envelope
xmlns:soap=" http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd=" http://www.w3.org/2001/XMLSchema"><so ap:Body>
Search WWH ::




Custom Search