Vous êtes sur la page 1sur 14

Aim

Creating a XSD and WSDL from scratch.

We want to create a WSDL file that defines an operation called CreateStudent.


CreateStudent should be a request response operation and should take a Student object
as input and return the Student ID as output. Student object stores the student name
and marks

Solution

This code is available under the accompanying zip file Project1.zip.

Create a Generic project

Copyright http://soatraining.hpage.com
Right click the Project1, and select New. Select All Items. Then enter WSDL in the top
left search box. It will show the following items.

Select WSDL Document (Web Services)

Copyright http://soatraining.hpage.com
It opens a wizard dialog. Enter the value as follows
WSDL Name: Student
Directory Name: Remove public-html/web-inf etc. Place the WSDL directly under the
project file.
Target Namespace: Usually we give some URL here. So enter
http://soatraining.hpage.com/Student
Create Port Type Checkbox: Check it
Name: ProcessStudent
Service Style: Document (default)

Press OK. It opens the WSDL document in design view.

Expand messages by clicking on +

Copyright http://soatraining.hpage.com
The design view is as follows

As you can see here, the wizard has created a porttype containing an operation named
NewOperation input and output messages as NewMessage and NewReturnMessage.
We would like to change these values.

Open the WSDL in source mode as its easy to modify it in this mode.

Change as follows
1 = StudentMessage
2 = StudentReturnMessage
3 = CreateStudent
4 = StudentMessage
5 = StudentReturnMessage

Copyright http://soatraining.hpage.com
Now, we need to define the structure of Student element. As of now, the in part is
defined as xsd:any, while we would like to have a student element here.

We would create the student definition in a separate xsd, and then import that xsd in
this wsdl document.

Creation of XSD

XSDs can be created in many ways.


1. Creating XSD from a given XML document
2. Creating the XSD from scratch.

We explore the first one. JDeveloper has a feature that it can generate an xsd file from
an xml document. To use this feature, lets add an XML document to our project.

Right click Project 1 > All Items > Enter XML in the search text box and select XML
Document

Copyright http://soatraining.hpage.com
The xml file is added to the project

Copyright http://soatraining.hpage.com
JDeveloper opens the empty xml file

Enter following values

<?xml version="1.0" encoding="windows-1252" ?>


<Student>
<Name>StudentName</Name>
<Marks>90</Marks>
</Student>

Now Right click Project 1 > All Items > Enter XML in the search text box and select XML
Document

Enter the values as follows


XML Schema: Student.xsd

Copyright http://soatraining.hpage.com
Directory: default
Target Namespace: http://soatraining.hpage.com/Student/types
XML Document, Browse: Select the sample xml file

Press OK.

In source mode

Copyright http://soatraining.hpage.com
The xsd looks fine. Note, JDeveloper has even intelligently given integer type to marks !.
If you need any modification, you can always do that now.

Now we would import this xsd in our wsdl. Open wsdl file and select the Schema tab

Open the property inspector too. If it is not visible, select it from View > Property
Inspector.

Right click <schema> node and select Insert inside schema > import

It add an import element, as follows

Copyright http://soatraining.hpage.com
In the source code things look like this

Back to the schema tab,

1. remove the namespace definition in the <schema>

2. From property inspector, select default for the elementFormDefault

3. Select the import node and enter the following values in the Property inspector
Select the next to the schemaLocation > Select Edit

Copyright http://soatraining.hpage.com
Browse to select Student.xsd

Enter the following value in the namespace


http://soatraining.hpage.com/Student/types

The schema looks as follows on the Schema tab

Copyright http://soatraining.hpage.com
In source tab, it’s as follows, after all modifications

Now, we want to change the StudentMessage so that it takes a Student as input. This
can be done from the design view. Select the part- xsd-any in and modify the element
from the property inspector, choosing Student.

The message part gets modified, but JDev shows a warning.

Copyright http://soatraining.hpage.com
This is coming because Student is in a different namespace
(http://soatraining.hpage.com/Student/types) than this WSDL document’s
targetNamespace (http://soatraining.hpage.com/Student). So the WSDL cannot find this
element.

We need to create an alias for http://soatraining.hpage.com/Student/types and then use


it to qualify Student

Add an alias named client to the definitions as shown

Now modify the part as follows. Type “client:” in front of Student. It will show a popup.
You can select the client:Student.

The return is a simple string. So we can use the string datatype from XSD standard.
Modify the part name return as follows

Note, we have used type, instead of element here.

Copyright http://soatraining.hpage.com
This completes the definition of the WSDL. Note, this WSDL is called Abstract WSDL as
it does not yet have bindings and service elements. These get usually added by the tools
(such as jdeveloper) during compilation.

Copyright http://soatraining.hpage.com

Vous aimerez peut-être aussi