Java Reference
In-Depth Information
<xs:complexType name="add">
<xs:sequence>
<xs:element name="i" type="xs:int"></xs:element>
<xs:element name="j" type="xs:int"></xs:element>
</xs:sequence>
</xs:complexType>
//... response omitted
</xs:schema>
According to the schema, you'll need to create an element called add that has two child ele-
ments in the given namespace, which will in turn hold integer values. Here's what it should
look like:
<tns:add xmlns:tns="urn:soacookbook.saaj">
<i>5</i><j>4</j>
</tns:add>
Of course, you need to have the XML structure for the header itself.
NOTE
Headers in SOAP 1.2 are not simply key/value pairs, as you may be used to seeing in SMTP or HTTP
headers. They must be full-blown XML info sets, including a namespace.
Here is a snippet of XML that conforms to the definition of the schema element pass-
wordHeader :
<SOAP-ENV:Header>
<passwordHeader xmlns="urn:soacookbook.saaj">
s3cr3t
</passwordHeader>
</SOAP-ENV:Header>
Now that you have an idea of what XML structure you need to create, let's go for it. Of course,
you could have a SOAP message template and replace values in it at runtime, or read it in
from a file, as we've seen in earlier recipes. But creating the entire thing programmatically is
more common and straightforward, so that's what we'll do here.
Building the client program
Now, you finally get to the point of this recipe, which is to write a program that creates a
SOAP client message, including an XML info set header, and invokes a remote web service.
In this case, you're pretending that there's some security on the web service and you need to
Search WWH ::




Custom Search