Sunday, July 4, 2010

Creating your own Webservices in JDeveloper11g Part 1 - Creating XML Schema


These days my mind is in webservices mode so i will show how to create your own webservices in JDeveloper.

Creating your own webservies is a 3 step process as follows Note: You can also create webservices from Java class directly
  1. Create a XML Schema (XML schema define the structure of the webserivces)
  2. Create WSDL Document (Define the operations of Webservices)
  3. Generate Webservice from WSDL and implement code (the logic behind) and of course Test and deploy the Webservice (Output) 
You can download the sample workspace for all 3 parts 
     This post will cover the first step which is Creating XML schema

    Use case example
    • We will have a webservice which takes a input of credit card number and return the status of creadit card VALID or INVALID from the database table column "creditcard_status"
    • Following script to create sample table with data which we will use in this example (you can run the script.sql available in the project file)

    create table CreditStatus
    (creditCard_number Number,
     creditCard_status varchar2(15 char));
     insert into creditstatus
    insert into creditstatus
    insert into creditstatus

      Enough talking lets cook the Hot and Spicy webservice dish :)

      • Create an application with Generic Template as shown in the slide

      •  Create a project inside named validateCreditCard

      • Right click choose New on the Project, Go to page All Technologies >  XML > XML Schema and Press OK
      • Enter the Schema name as shown in the slide Make sure to extend the path by \public_html\WEB-INF\xsd

      • According to our scenario we need to define what will come as Input and what would be the output, so we will create a request parameter and response as CreditCardReques and CreditCardResponse.
      • Rename the first element to "CreditCardRequest", drag a sequence element from the component pallete to the CreditCardRequest element, drag a "element" component to the sequence component as shown in the slide, change the name to "ccNumber" and type to xsd:integer
      • This will act as our Input request parameter

      • Now do the same for output as well, drag the element component to the top schema element, drag a sequence, drag a element on sequence and renamed to "ccStatus" and type as "xsd:string" 
      • Your schema would look like this

      This is end of part 1

      Next Step: We will create a WSDL document, define the operation that webservice will perform and bind our XML schema with that WSDL.

      Happy JDeveloping,

      No comments:

      Post a Comment