Hi,

Jay SenSharma

Jay SenSharma

How to build a WebService from a WSDL ? Especially when it uses some Externally Located Schema.

Step 1). DownLoad the WSDL and paste it in the Current Directory. And If the WSDL is using some External XSDs then Explicitly download those XSDs in the Current Directory.

Step 2). In the downloaded WSDL Please Modify the “XSDLocation” Attribute in the Downloaded WSDL Like below….
SimpleService.WSDL

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!-- Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is Oracle JAX-WS 2.1.3-07/10/2008 08:41 PM(bt). -->
<definitions targetNamespace="http://test.webservicefromWSDL/" name="SimpleService" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://test.webservicefromWSDL/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
<types>
<xsd:schema>
<xsd:import namespace="http://test.webservicefromWSDL/" schemaLocation="SimpleService_schema1.xsd"/>
</xsd:schema>
</types>
<message name="hello">
<part name="parameters" element="tns:hello"/>
</message>
<message name="helloResponse">
<part name="parameters" element="tns:helloResponse"/>
</message>
<portType name="Simple">
<operation name="hello">
<input message="tns:hello"/>
<output message="tns:helloResponse"/>
</operation>
</portType>
<binding name="SimplePortBinding" type="tns:Simple">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="hello">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="SimpleService">
<port name="SimplePort" binding="tns:SimplePortBinding">
<soap:address location="http://s906648/SimpleService/SimpleService"/>
</port>
</service>
</definitions>

SimpleService_schema1.xsd

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema version="1.0" targetNamespace="http://test.webservicefromWSDL/" xmlns:tns="http://test.webservicefromWSDL/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="hello" type="tns:hello"/>
<xs:element name="helloResponse" type="tns:helloResponse"/>
<xs:complexType name="hello">
<xs:sequence/>
</xs:complexType>
<xs:complexType name="helloResponse">
<xs:sequence>
<xs:element name="return" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:schema>

Step3). Develope the ANT “build.xml” like following:

<project name="GenerateWS" default="all">
<property name="build" value="output" />
<property name="adminurl" value="t3://localhost:7001" />
<property name="serverName" value="AdminServer" />
<property name="ear.dir" value="EJB_JAXWS_Ear" />

<taskdef name="jwsc"    classname="weblogic.wsee.tools.anttasks.JwscTask" />
<taskdef name="wsdlc" classname="weblogic.wsee.tools.anttasks.WsdlcTask"/>
<target name="all" depends="generate-from-wsdl"/>

<target name="generate-from-wsdl">
      <wsdlc  srcWsdl="SimpleService.wsdl"
              destJwsDir="jarJws"
              destImplDir="."
              packageName="ws"
              type="JAXWS"/>
</target>

<target name="build-service">
<jwsc srcdir="." destdir="output/EJB_WS_Ear">
    <jws file="ws/SimpleService_SimplePortImpl.java"
         compiledWsdl="jarJws/SimpleService_wsdl.jar" />
    </jwsc>
</target>

<target name="deploy" depends="build-service">
<wldeploy action="deploy" source="output/EJB_WS_Ear"
          user="weblogic" password="weblogic" verbose="true"
          failonerror="yes" adminurl="${adminurl}"
          targets="${serverName}" />
</target>

<target name="redeploy">
<wldeploy action="redeploy" source="output/EJB_WS_Ear"
          user="weblogic" password="weblogic" verbose="true"
          failonerror="true" adminurl="${adminurl}"
          targets="${serverName}" />
</target>
</project>

Step4). Run the Ant Task —“generate-from-wsdl”  (before this you need to run the setDomainEnv.sh or setWLSEnv.cmd).
C:DELETEWSDLC_TO_Service>ant generate-from-wsdl

Output:
Buildfile: build.xml

generate-from-wsdl:
[wsdlc] Download file [SimpleService_schema1.xsd] to C:DOCUME~1JAYKUM~1LOCALS~1Temp_ckr59b
[wsdlc] Download file [SimpleService.wsdl] to C:DOCUME~1JAYKUM~1LOCALS~1Temp_ckr59b
[wsdlc] srcWsdl is redefined as [ C:DOCUME~1JAYKUM~1LOCALS~1Temp_ckr59bSimpleService.wsdl ]
[wsdlc] Consider using <depends>/<produces> so that wsimport won’t do unnecessary compilation
[wsdlc] parsing WSDL…

[wsdlc] generating code…

[wsdlc] compiling code…

[wsdlc] Note: C:DELETEWSDLC_TO_ServicejarJwsgeneratedwsSimpleService.java uses unchecked or unsafe operations.

[wsdlc] Note: Recompile with -Xlint:unchecked for details.
[AntUtil.deleteDir] Deleting directory C:DOCUME~1JAYKUM~1LOCALS~1Temp_ckr59b

BUILD SUCCESSFUL
Total time: 2 seconds
C:DELETEWSDLC_TO_Service>
——————-

Step5). Above execution will generate two Directories in the Current Directory “ws” and “jarJws”.
You will find that a WebService class “SimpleService_SimplePortImpl.java” is generated inside the “ws” directory like following.

package ws;
import javax.jws.WebService;
import javax.xml.ws.BindingType;
/**
* This class was generated by the JAX-WS RI.
* Oracle JAX-WS 2.1.3-06/19/2008 07:03 PM(bt)
* Generated source version: 2.1
*
*/
@WebService(portName = "SimplePort", serviceName = "SimpleService", targetNamespace = "http://test.webservicefromWSDL/", wsdlLocation = "/wsdls/SimpleService.wsdl", endpointInterface = "ws.Simple")
@BindingType("http://schemas.xmlsoap.org/wsdl/soap/http")
public class SimpleService_SimplePortImpl
implements Simple
{
public SimpleService_SimplePortImpl() {
}

/**
*
* @return
*     returns java.lang.String
*/
public String hello() {
//replace with your impl here
return null;
}

}

Modify the "wsSimpleService_SimplePortImpl.java" and
Provide the implementation to the String hello() method according to your requirement...

Example:
public String hello() {
System.out.println("nnt Hello Mr...Jack..."+new java.util.Date());
return "nnt Hello Mr...Jack..."+new java.util.Date();
}

Step6). Now run the ANT task “deploy” it will build your WebService using JWSC and then It will deploy it:
OUTPUT:

C:DELETEWSDLC_TO_Service>ant deploy
Buildfile: build.xml

build-service:
[jwsc] JWS: processing module /ws/SimpleService_SimplePortImpl
[jwsc] Parsing source files
[jwsc] Parsing source files
[jwsc] 1 JWS files being processed for module /ws/SimpleService_SimplePortImpl
[jwsc] JWS: C:DELETEWSDLC_TO_ServicewsSimpleService_SimplePortImpl.java Validated.
[jwsc] <WSEE:1>URIs = []<TylarBindingsBuilderBase.getTylarUris:52>
[jwsc] Dependent class ws.Simple was not found in the classpath or sourcpath.
[jwsc] Compiling 8 source files to C:DOCUME~1JAYKUM~1LOCALS~1Temp_lt0r03
[jwsc] Note: C:Documents and SettingsjaykumarsLocal SettingsTemp_lt0r03wsSimpleService.java uses unchecked or unsafe operations.

[jwsc] Note: Recompile with -Xlint:unchecked for details.
[jwsc] Deleting existing module outputFile C:DELETEWSDLC_TO_ServiceoutputEJB_WS_EarwsSimpleService_SimplePortImpl.war
[jwsc] Unable to delete module outputFile C:DELETEWSDLC_TO_ServiceoutputEJB_WS_EarwsSimpleService_SimplePortImpl.war
[jwsc] Building jar: C:DELETEWSDLC_TO_ServiceoutputEJB_WS_EarwsSimpleService_SimplePortImpl.war
[jwsc] Created JWS deployment outputFile: C:DELETEWSDLC_TO_ServiceoutputEJB_WS_EarwsSimpleService_SimplePortImpl.war
[jwsc] [EarFile] Application File : C:DELETEWSDLC_TO_ServiceoutputEJB_WS_EarMETA-INFapplication.xml
[AntUtil.deleteDir] Deleting directory C:DOCUME~1JAYKUM~1LOCALS~1Temp_lt0r03

deploy:
[wldeploy] weblogic.Deployer -verbose -noexit -source C:DELETEWSDLC_TO_ServiceoutputEJB_WS_Ear -targets AdminServer -adminurl t3://loca
lhost:7001 -user weblogic -password ******** -deploy
[wldeploy] weblogic.Deployer invoked with options:  -verbose -noexit -source C:DELETEWSDLC_TO_ServiceoutputEJB_WS_Ear -targets AdminSer
ver -adminurl t3://localhost:7001 -user weblogic -deploy
[wldeploy] <Dec 18, 2009 4:32:49 PM IST> <Info> <J2EE Deployment SPI> <BEA-260121> <Initiating deploy operation for application, EJB_WS_Ear
[archive: C:DELETEWSDLC_TO_ServiceoutputEJB_WS_Ear], to AdminServer .>
[wldeploy] Task 1 initiated: [Deployer:149026]deploy application EJB_WS_Ear on AdminServer.
[wldeploy] Task 1 completed: [Deployer:149026]deploy application EJB_WS_Ear on AdminServer.
[wldeploy] Target state: deploy completed on Server AdminServer
[wldeploy]
[wldeploy] Target Assignments:
[wldeploy] + EJB_WS_Ear  AdminServer

BUILD SUCCESSFUL
Total time: 5 seconds
C:DELETEWSDLC_TO_Service>

Step 7). Test Your WebService using WebLogic TestClient through AdminConsole.
Thanks

Jay SenSharma

If you enjoyed this post, please considerleaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.