Web Service Passing Binary Data, pt 5: Modifying the Schema and WSDL Files
In this section, you add the WSDL file and schema file to our application. Then you modify them to
interpret arrays of bytes as Images. You also
adjust various parts of the application to correctly locate the schema and WSDL file. In the
process, you are introduced to various tools in the IDE that help you with WSDL and Schema files.
Modifying the Schema File and WSDL Files to Pass Binary Data
In the following procedure, you create modified WSDL and XML Schema files for the web service that you created in a previous tutorial. The modified WSDL and Schema files enable the web service and the clients that consume it to parse JPEG image data that is passed as binary data.
To modify the WSDL and Schema files:
Expand the web application until you reach the wsdl node:
Note: Currently the node is empty. The WSDL file and schema
are generated at deployment, because you have been using default setings.
Therefore this node, which would normally house them, is empty. Now
that you want to interpret arrays of bytes as Images, you need to provide
your own WSDL file and schema. We will put them in this node.
Right-click the wsdl node and choose New > Other. The New File wizard opens. Open the XML category and select XML Schema.
Name the schema file FlowerService.xsd.
Repeat Step 2,
but this time from the XML category select WSDL Document. Name the file
FlowerService.wsdl.
You should now see the following
in the wsdl node:
Copy the content of the WSDL file in the browser
to the template you created above. If you used the
defaults when creating and deploying the web service,
the WSDL file should be here:
Edit the WSDL file and insert the namespace
declarations. These decarations are necessary for the WSDL to be valid.
Replace the lines at the beginning of the file:
<!--
Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.2-hudson-182-RC1.
-->
<!--
Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.2-hudson-182-RC1.
-->
<definitions targetNamespace="http://album.flower/" name="FlowerService">
Edit the schema file and insert the namespace
declarations. These decarations are necessary for the schema file to be valid.
Replace the lines at the beginning of the file:
<!--
Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.2-hudson-182-RC1.
-->
<xs:schema version="1.0" targetNamespace="http://album.flower/">
Next, we will change the WSDL file so that our
local schema file is referenced instead of the one
that is on-line. Open the WSDL file in the Design mode,
as shown below.
Expand the Types node. Right-click the
Referenced Schema node.Choose Add > Import.
The Add Import dialog opens.
As shown below, you can now browse to the schema file and select it:
Click OK.
Delete the other schema reference, which refers to the online
schema file, which we do not want to refer to anymore, and then
you will see that you can access nodes from the schema file,
indicating that you have now correctly referenced it:
We need to explicitly make the application server use our
own version of the WSDL file, otherwise the application server
will generate its own WSDL file, from our web service's annotations.
You should now see the following in the web service class:
Finally, the point of this whole section is to have a modified
schema file that specifies the expected content type of the
return element. To identify the return element in the schema file,
open the schema file and look at the line below, as well as the
code in line 39, both of which may be on different lines in your own
application:
Keep all the existing elements, but
add the following attributes to both:
You should now see the following in the same lines:
Now, when you redeploy the web service to the Tester
application, and invoke one of the operations, you will
see that an image is correctly returned:
Now that the Tester application has confirmed that images
are correctly being returned, we can create our Swing client to
retrieve and display them.
Note: You can find correctly modified versions of the WSDL and Schema files in the downloaded sample project. Both files are in the folder web/WEB-INF/wsdl.
To send comments and suggestions, get support, and keep informed on the latest
developments on the NetBeans IDE Java EE development features, join
the mailing list.