Sample implementation script and WSDL document

The following document literal web service returns a stock quotation for a ticker symbol. This limited example returns only a value for the IBM® ticker; all other arguments result in a SOAP fault.

The implementation script is as follows:
// parse the request document
var doc = new XmlDocument(soapMessage);

// get the ticker parameter
var ticker = parseXMLNode("ibm:ticker");

// we only give out ibm quotes around here...
if (ticker == "IBM") {
out.println("<ibm:getStockQuoteResponse
xmlns:ibm=\"http://ibm.com/wpc/test/stockQuote\">");
out.println("<ibm:response>123.45</ibm:response>");
out.println("</ibm:getStockQuoteResponse)");
}
else {
soapFaultMsg.print("Only quotes for IBM are supported");
}

Table 1. Sample scripts
Method Sample code
Document literal style
<element name="getStockQuote"/>
<complexType>
<sequence>
<element name="ticker" type="xsd:string"/>
</sequence>
</complexType>
</element>
<element name="getStockQuoteResponse"/>
<complexType>
<sequence>
<element name="response" type="xsd:decimal"/>
</sequence>
</complexType>
</element>
Java™
java.math.BigDecimal getStockQuote(String ticker);
WSDL
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/"xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"xmlns:xs="http://www.w3.org/2001/XMLSchema"xmlns:y="http://ibm.com/wpc/test/stockQuote"targetNamespace="http://ibm.com/wpc/test/stockQuote">
<types>
<xs:schema targetNamespace="http://ibm.com/wpc/test/stockQuote"elementFormDefault="qualified">
<xs:element name="getStockQuote">
<xs:complexType>
<xs:sequence>
<xs:element name="ticker" type="xs:string" nillable="false"/>
</xs:complexType>
</xs:element>
<xs:element name="getStockQuoteResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="response" type="xs:decimal"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
</types>
<message name="getStockQuoteRequest">
<part name="parameters" element="y:getStockQuote"/>
</message>
<portType name="StockQuotePortType">
<operation name="getStockQuote">
<input message="y:getStockQuoteRequest"/>
<output message="y:getStockQuoteResponse"/>
</operation>
</portType>
<binding name="StockQuoteBinding" type="y:StockQuotePortType">
<soap:binding style="document"transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="getStockQuote">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="StockQuoteService">
<port name="StockQuotePort" binding="y:StockQuoteBinding">
<soap:addresslocation="http://example.wpc.ibm.com/services/StockQuoteService"/>
</port>
</service>
</definitions>
The result of running this script is that IBM Product Master does the following things:
  1. Receives a SOAP request from the Axis SOAP stack.
  2. Validates the request message against the previous schema.
  3. Starts the web service trigger script. The input variables are:
    - operationName = "getStockQuote"- message = "<getStockQuote>
    <ticker>IBM</ticker>
    </getStockQuote>"
    
    The trigger script writes the response to the out writer:
    - out = "<getStockQuoteResponse>
    <response>83.76</response>
    </getStockQuoteResponse>"
  4. Validates the response against the previous schema.
  5. Sends the entire SOAP response back to the client through the Axis SOAP stack.