Web Service Passing Binary Data, pt 4: Modifying the Schema and WSDL Files
In this lesson, you add the WSDL file and schema file to the web application. Then you modify the schema file to
interpret arrays of bytes as Images. You also
edit the web service source code 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.
You can apply the procedure in this section to any JAX-WS web service, to pass any MIME type as binary data. Starting with a web service that passes binary data, as you created in Lessons 2 and 3, you customize the service's WSDL and XML schema. In the customized XML schema file, you add an expectedContentTypes="mime_type" attribute to the return element for the binary data. This attribute informs the client that it should map the binary data to a Java type (as per MIME > Java type mapping) instead of to an array of bytes. In this tutorial, you map the binary data to java.awt.Image, but you can map the binary data to any of the Java types given in the JAXB 2.0 specification, as described in the JAX-WS Users Guide.
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:
In the Projects window, expand the FlowerService web application node until you reach the WEB-INF node.
Right-click the WEB-INF folder and select New > Folder. (You might need to select New > Other, then the Other category).
Click Next. The Name and Location page opens. Name the folder wsdl.
Click Finish. The folder wsdl appears in the Projects Window.
Expand the Web Services node and right-click the FlowerService node. Choose Generate and Copy WSDL...
The Generate and Copy WSDL dialog opens with a navigation tree. Navigate to the wsdl folder
you created (FlowerAlbumService > web > WEB-INF > wsdl)
and click OK.
You now see FlowerService.wsdl and FlowerService_schema1.xsd
in the wsdl node. You also see a new node for Generated Sources (jax-ws).
Explicitly make the application server use your
own version of the WSDL file. Otherwise the application server
will generate its own WSDL file.
Open FlowerService.java and
locate the @WebService annotation. Add to this annotation the parameter wsdlLocation="WEB-INF/wsdl/FlowerService.wsdl" as shown below:
schema file FlowerService_schema1.xsd so it specifies the expected content type of the
return element. To identify the return element in the schema file,
open the schema file and find the complex types getThumbnailResponse and getFlowerResponse: