hi
Since your webservice is going to talk to database and return XML resultset to the client, you possibly can do this.
In the following example I am using Apache Axis toolkit. If you are using different toolkit this will give you an idea hopefully (Exception handling code is not included.. )-
Configuration info in server-config.wsdd
<service name="DataService" style="message">
<parameter name="className" value="webservice.RequestManager"/>
<parameter name="allowedMethods" value="invokeService"/>
</service>
Notice that style is set to message. So you can exchange generic XML message with your client.
The invokeService method of webservice class will look something like this
public Document invokeService(Document
doc) throws SOAPException {
Document response = null;
try {
Element element = doc.getDocumentElement();
// dataSerivce is the class that talks to database.
// Can be normal
Java Class / Session bean anything that
// creates the XML org.w3c.dom.Document Object
DataService dataService = new DataService();
/**
*In my case the actual message that client sends has
*dataservice as the root tag
*/
NodeList xmlPayload = element
.getElementsByTagNameNS(properties.getDefaultNameSpace() ,
"dataservice");
DocumentBuilder builder = getDocumentBuilder();
/*
Create a Document Object From It.
*/
Document xmlRequest = builder.parse( new InputSource(new
StringReader(DOM2Writer.nodeToString(xmlPayload.item
(0),false))));
/*
Get Response.
*/
response = dataService.invokeService(xmlRequest);
System.out.println(
XMLUtils.DocumentToString(response));
}
catch (Exception ex) {
ex.printStackTrace();
throw new SOAPException (ex.getMessage());
}
return response ;
}// end invokeService
private DocumentBuilder getDocumentBuilder() throws DataServiceException {
DocumentBuilder builder = null;
try {
DocumentBuilderFactory df = DocumentBuilderFactory.newInstance();
df.setValidating(false);
df.setNamespaceAware(true);
builder = df.newDocumentBuilder();
} catch (.... ){}
return builder
}
And your client program will something like this -
public static void main(String[] args) {
try {
DocumentBuilderFactory df = DocumentBuilderFactory.newInstanc();
df.setValidating(false);
df.setNamespaceAware(true);
DocumentBuilder builder = df.newDocumentBuilder();
// This is the sample XML request
// read from file. IN real life client will have its own logic
// to generate it
Document doc = builder.parse(new File("ds.xml"));
Service service = new Service();
Call call = (Call) service.createCall();
call.setTimeout(new Integer(3080000));
String endpoint
= "http://<serverName>
ort/MyWebApp/services/DataService";
call.setTargetEndpointAddress(new URL(endpoint));
Vector result = (Vector) call.invoke
(new Object[] {new SOAPBodyElement(doc.getDocumentElement())});
SOAPBodyElement sbe = (SOAPBodyElement) result.get(0);
Document resultDoc = sbe.getAsDocument();
//System.out.println("received " + XMLUtils.DocumentToString(resultDoc));
} catch ( Exception e ) {
e.printStackTrace();
System.out.println("Error " + e.getMessage());
}
Hope this helps. You can exchange any generic XML message with this.