Java Reference
In-Depth Information
The important part of this code is getting the
RequestContext
from the
Dispatch
object, and
using constants in the
Dispatch
class to specify that you want to use the
SOAPAction
header,
allowing that to specify the action that the service dictates:
//Say we want to use SOAPAction
dispatch.getRequestContext().put(
Dispatch.SOAPACTION_USE_PROPERTY, "1");
//Specify our value
dispatch.getRequestContext().put(
Dispatch.SOAPACTION_URI_PROPERTY,
"http://www.webserviceX.NET/GetQuote");
The preceding code indicates that you want to specify the
SOAPAction
property ourselves,
overriding the default. Next, you indicate the actual value to use. It will produce a header in
the HTTP request that looks like this:
SOAPAction: "http://www.webserviceX.NET/GetQuote"
NOTE
Here you use “1” to indicate a Boolean true. But you could spell out the word true as well; the
SOAP specification is happy with either. This works for false and 0 too, and not just with
SOAPAc-
tion
—you can also use these values on items like
mustUnderstand
and others.
The result includes data about the market and share activity:
Created Service: {http://www.webserviceX.NET/}StockQuote
Created Request:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="...">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<GetQuote xmlns="http://www.webserviceX.NET/">
<symbol>JAVA</symbol>
</GetQuote>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Got Response:
<soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">