• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Sending requests in xml

 
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello -

I am able to write web service client and server and they are all working fine.

What I have heard about web service is that the exchange of information is in xml. What does that mean? How do I send request in xml?
Should I send it in the form of a string? How should I do that?

My project is web service extensive. and all the request and response is in xml. This is the first time I am working with web services. Kindly help me understand.

Best,
Hari Priya
 
author and deputy
Posts: 3150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Hari priya:

What I have heard about web service is that the exchange of information is in xml. What does that mean? How do I send request in xml?
Should I send it in the form of a string? How should I do that?


This means that the SOAP request and SOAP response will be in XML format, your web serivces tool(like Apache axis) will do this for you, so you don't need to send it as string or other formats. You have to just invoke the webservice operation and read back the response. If you want to see what kind of XML is being transmitted between client and server you can use TCP/IP sniffers or SOAPMonitor tool from Apache Axis.
 
Hari priya
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Balaji for your response.

For my requirement, I am supposed to write a service which reads data from a database sends teh result as an xml document to the client.

The client has to parse the resulting xml to read teh data.

So, here, I will be generating an xml and will be sending it as a string or document. Is this equivalent to the SOAP response that you have explained me? If not how is this response string or document will be sent?

Is it possible to send the query result as a SOAP response itself or as a strign or as a document object?

Kindly help me as I got confused here between the soap response and this one.

Many thanks for taking time.
Hari Priya
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Soap is a protocol to carry your data from server to client. The soap message will have two parts Header(optional) and body. The body of the soap message is nothing but your xml. Once this soap message is composed, you will send it as your request/response.
 
Hari priya
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello -

Thank you for your response Sonia. I understand it much better now. But I have another question now.

This is the statement, that I use to to hold the response



should I set the return type of the service method to SOAPEnvelope right?
Don't I have to set the return type as in



Thanks again!
 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
If you want to access the information sent back to you from the webservice then you definately want to get handle to response if not then don't worry about it.
e.g
when you invoke a service method, a object is returned, you can cast it to string if you think its returning a string back as shown below:

Does that help.
-DV
 
Hari priya
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi -

Thanks for the reply Dharamvir. My question is - what shoud we set the return type to if my web service returns a SOAPEnvelope.

Hari Priya
 
Dharamvir (DV) Punia
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Priya,
This is what you looking for:


I have never tried this but you can give a try:



Here is also link to the tutorial as well: SAAJ

Does this help.
-DV
[ October 27, 2004: Message edited by: Dharamvir (DV) Punia ]
 
Hari priya
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Dharamvir -

Thanks for trying to help me. I understand what you are saying. The return type is a SOAPEnvelope. So, do I need to set the return type to something before I invoke the call using call.setReturnType()

Thank you!
Hari Priya
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Dharamvir (DV) Punia
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Priya,
I am sorry that you got confused, Yes you are right, you have to set the return type before invoking the service.

e.g
// set the return type first, in this case you are setting your type to String


// now invoke the service and get the return value and assign to whatever your return type is , in this case its a string as you set your type to String.


Is that good. No Confusion now

-DV
 
Hari priya
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Neelesh for giving a good example. I will implement teh web service and get back for problems.

Thanks Dharamvir for getting back. Regards,
 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where Can i found the good examples for webservices using Axis
 
siva kumar
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Priya

Can you give some webservices server examples
 
Hari priya
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Shiv Kumar -

I have seen the jws files in teh web-app directory of axis and have been working with that.

The steps for building a web service are given in the docs folder of axis.
They are all html files. Particularly the user-guide.html

That is where I have started.

Thanks,
Priya
 
siva kumar
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Hari priya:
Hi Shiv Kumar -

I have seen the jws files in teh web-app directory of axis and have been working with that.

The steps for building a web service are given in the docs folder of axis.
They are all html files. Particularly the user-guide.html

That is where I have started.

Thanks,
Priya

 
siva kumar
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi priya

thnks
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear seniors

Server side:
i have one imlimentation class and interface class in implimentation class i have to get the SOAP message object from client and process and give the result SOAP message to the client.In interface i declare that method"onMessage" it returns SOAPMessage object.

Client side:
i have one client class and it read the xml file and convert to the soap and i create the object for the server side interface class and using this object i pass the client side soap message object to the server iinterface.and process it

in this i got the soap message but i cant send the SOAPMessage object to this server interface......please any one give me the methd to send the soap messager object to the server interface class

"""ServiceFactory serviceFactory = ServiceFactory.newInstance();
Service helloService = serviceFactory.createService(helloWsdlUrl,new QName(nameSpaceUri, serviceName));
pkgClient.JAXMServiceIF objSoap=(pkgClient.JAXMServiceIF);
helloService.getPort(new QName(nameSpaceUri, portName),pkgClient.JAXMServiceIF.class);
SOAPMessage soapResult=objSoap.onMessage(msg);""""

this my code to invoke the server interface JAXMServiceIF..i create one object for the interface class in client pkgClient is my client package


it gave me the error in the SOAPMessahge soapResult = objSoap.onmessage(msg)

the error is :: cannot be applied to SOAPMessage soapResult = objSoap.onMessage(msg)


please give me the solution
 
sakthi vadivelan
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello hari priya mam please give me the idea or any member please give me the idea about how to send a soapmessage to server without using connection.call method

thanks a lot
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello sir/madam,

Now i want to send a soap messsage from client to server. Our server has one interface class and one implementation class.

Connection.call() method is not used for our requirement. because this method dirctly specifie the implementaion calss. but we need to specifie the interface class.Thus is our requirement.
 
lallitha devi
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello all,

my requirement is send soap message from client to server. so here im using onMessage() method. but this method doesn't support.so now i am using call.invoke(); here im passing soap envelope. now also i am getting 2 error like this


1. [exec] error: Type "javax.xml.soap.SOAPElement" implements more than one interface, interfaces: "javax.xml.soap.Nod
e", "org.w3c.dom.Element" ...
[exec] Result: 1

2. [exec] error: XML reader error: java.io.EOFException: Unexpected end of ZLIB input stream

Give me ur valuable idea.......
thanks
reply
    Bookmark Topic Watch Topic
  • New Topic