943,898 Members | Top Members by Rank

Jan 7th, 2008
0

Accessing a Web Service

Expand Post »
Hey guys, I'm really new to this I've managed to setup a Web Service and a Client to access the service within Eclipse. However, I want to access a Web Service that already exists. From what I understand, that service must have a WSDL (Web Services Description Language) for it to be used by Eclipse. The Web Service that I want to interact with does not have a WSDL or at the very least it doesn't have a .wsdl file. Um I'm hoping that's possible or perhaps I've confused the application I'm trying to access for a Web Service?

I'm using a pre-defined platform that can process SOAP requests. Just to confirm the following is a SOAP request hey?
xml Syntax (Toggle Plain Text)
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <GetObservation service="SOS" version="0.0.31"
  3. xmlns="http://www.opengeospatial.net/sos"
  4. xmlns:gml="http://www.opengis.net/gml"
  5. xmlns:ogc="http://www.opengis.net/ogc"
  6. xmlns:ows="http://www.opengeospatial.net/ows"
  7. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  8. xmlns:swe="http://www.opengis.net/swe">
  9. <offering>TAG_READING</offering>
  10. <eventTime>
  11. <ogc:During>
  12. <gml:TimePeriod>
  13. <gml:beginPosition>2007-12-10T08:00:00</gml:beginPosition>
  14. <gml:endPosition>2007-12-13T12:00:00</gml:endPosition>
  15. </gml:TimePeriod>
  16. </ogc:During>
  17. </eventTime>
  18. <procedure>urn:ogc:def:procedure:wavertrend_rx201_sensory_web</procedure>
  19. <observedProperty>urn:ogc:def:phenomenon:OGC:1.0.30:temperature</observedProperty>
  20. <featureOfInterest>
  21. <ObjectID>COR01</ObjectID>
  22. </featureOfInterest>
  23. <resultFormat>text/xml;subtype="OM"</resultFormat>
  24. </GetObservation>

I want to be able to send requests via a Java program and interpret these results within the program. Can anyone please tell me how this is done? I'd need the appropriate .jar files hey? I'm not sure what they are or if they even come with Eclipse. The version of Eclipse that I have is the JaveEE one. Please advise
Similar Threads
Reputation Points: 56
Solved Threads: 11
Junior Poster
PoovenM is offline Offline
147 posts
since Aug 2006
Jan 8th, 2008
0

Re: Accessing a Web Service

I think that a Web Service offers remote procedure calls (methods that can be called over the internet). The application I'm working with is really a servlet that accepts xml requests so I guess it isn't a web service? I'm a bit unsure as to how I would perform such the xml request in Java though. I think that I'd need to create a URL object that points to the actual servlet?
java Syntax (Toggle Plain Text)
  1. URL service = new URL("http://localhost:8080/52nSOSv2/sos");
  2. URLConnection connection = service.openConnection();
  3. connection.setDoOutput(true);
  4. connection.setDoInput(true);
  5. connection.setUseCaches(false);
  6. connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
I'm not really sure what other parameters are used in setRequestProperty but can I simply create an output stream and write the xml request to it?
java Syntax (Toggle Plain Text)
  1. ObjectOutputStream out = new ObjectOutputStream(connection.getOutputStream());
  2. String request = ""; //xml request with correct escape sequences
  3. out.writeChars(request);
It doesn't seem to be working out, can someone please advise?
Reputation Points: 56
Solved Threads: 11
Junior Poster
PoovenM is offline Offline
147 posts
since Aug 2006
Jan 8th, 2008
1

Re: Accessing a Web Service

hi,

web service soap interface is defined by a wsdl file.
you can manually write a wsdl file or you can use some tools to generate the same(preferred way).

now, this wsdl file will work as a contract between soap server and soap client .
both server and the client can use this file to generate the stub files wrt soap methods.

I m not sure whether u was asking the same or you have some other doubt!!

Have fun with it!!

Manoj
Reputation Points: 12
Solved Threads: 1
Newbie Poster
manojkumar2004 is offline Offline
13 posts
since Nov 2007
Jan 8th, 2008
0

Re: Accessing a Web Service

Thanks for replying! So I should find a .wsdl file somewhere within the application if I was indeed working with a web service? Then I most definitely do not have a Web Service. That's one doubt cleared up thank you!

Now I'm not sure how to interact with the serlvet. The Java program I'm writing must be able to send requests in the form of xml to the servlet and get the response back. Hmmm this sounds like something for the JSP forum. I've been reading up on servlets bust still can't get it right. The error looks something like this: An xml error occurred when parsing the request: XML Exception: error: Illegal XML character: 0x0
Reputation Points: 56
Solved Threads: 11
Junior Poster
PoovenM is offline Offline
147 posts
since Aug 2006
Jan 8th, 2008
0

Re: Accessing a Web Service

hi,

for a web service method....input and output parameters should be an xml document.

let me tell me the basic logic.........

wsdl file is nothing but is an interface(just like some other java interface) and you should have some .java file which is implementing this interface.

wsdl file contains the information about the name of the methods, input/output parameters , message format, binding information, url's etc....,

so just like any other class what you have to do is to get the access of wsdl file(soap interface) from some other code(servlet/c# code/c++ code) and call the respective interface - as simple as that....

i dont have much idea in servlets...but if u want i can tell u with example how to access the same from c# code.

Have fun with it!!

Manoj
Reputation Points: 12
Solved Threads: 1
Newbie Poster
manojkumar2004 is offline Offline
13 posts
since Nov 2007
Jan 8th, 2008
0

Re: Accessing a Web Service

I understand that the wsdl file is written in xml and describes what remote methods (which could be regarded as services) are accessible and what their parameters are. I noticed that in Eclipse one can import a war file. I've done that and it Eclipse automatically generates the wsdl file. However, the import process isn't totally successful and the project itself has alota xml errors; errors that I'm not sure how to resolve. What I don't understand is that the wsdl file describes access to the servlet. A servlet has methods that are automatically invoked whenever access to a servlet is invoked. So instead of actually using SOAP, one would be able to simply POST to a serlvet. But I suppose being able to POST using SOAP could be useful in my application. Regardless, I still can't seem to get the project up so I can't test it. Thank you for your help Manoj! I wish I could just POST to the servlet as if I was using a HTML form but within a standard Java Application.
Reputation Points: 56
Solved Threads: 11
Junior Poster
PoovenM is offline Offline
147 posts
since Aug 2006
Jan 9th, 2008
0

Re: Accessing a Web Service

one update from my side...if yuo are using sevlets then better use jsp with it- no need to call any html form or something.
Reputation Points: 12
Solved Threads: 1
Newbie Poster
manojkumar2004 is offline Offline
13 posts
since Nov 2007
Jan 9th, 2008
0

Re: Accessing a Web Service

JSP is really a cool extension of HTML. I think the most common way to interact with a servlet via a JSP is to use the HTML <form> tag. I have managed to successfully create a connection to the servlet via a standard Java application. The thing I completely overlooked was that the xml request that I was sending had to be sent in URL encoding. If anyone’s interested, this is who I've done it:
java Syntax (Toggle Plain Text)
  1. URL service = new URL("http://localhost:8080/52nSOSv2/sos");
  2. URLConnection connection = service.openConnection();
  3. connection.setDoOutput(true);
  4. connection.setDoInput(true);
  5. connection.setUseCaches(false);
  6. connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
  7. DataOutputStream out = new DataOutputStream(connection.getOutputStream());
  8. String request = URLEncoder.encode("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
  9. "<GetObservation service=\"SOS\" version=\"0.0.31\" " +
  10. "xmlns=\"http://www.opengeospatial.net/sos\" " +
  11. "xmlns:gml=\"http://www.opengis.net/gml\" " +
  12. "xmlns:ogc=\"http://www.opengis.net/ogc\" " +
  13. "xmlns:ows=\"http://www.opengeospatial.net/ows\" " +
  14. "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " +
  15. "xmlns:swe=\"http://www.opengis.net/swe\">" +
  16. "<offering>TAG_READING</offering>" +
  17. "<eventTime>" +
  18. "<ogc:During>" +
  19. "<gml:TimePeriod>" +
  20. "<gml:beginPosition>2001-12-10T08:00:00</gml:beginPosition>" +
  21. "<gml:endPosition>2008-12-13T12:00:00</gml:endPosition>" +
  22. "</gml:TimePeriod>" +
  23. "</ogc:During>" +
  24. "</eventTime>" +
  25. "<procedure>urn:ogc:def:procedure:wavertrend_rx201_sensory_web</procedure>" +
  26. "<observedProperty>urn:ogc:def:phenomenon:OGC:1.0.30:temperature</observedProperty>" +
  27. "<featureOfInterest>" +
  28. "<ObjectID>COR01</ObjectID>" +
  29. "</featureOfInterest>" +
  30. "<resultFormat>text/xml;subtype=\"OM\"</resultFormat>" +
  31. "</GetObservation>", "UTF-8");
  32. System.out.println(request);
  33. out.writeBytes(request);
  34. out.flush();
  35. out.close();
  36. DataInputStream in = new DataInputStream(connection.getInputStream());
  37. String line = "";
  38. System.out.println("Response!!");
  39. while ((line = in.readLine()) != null)
  40. System.out.println(line);

This site was rather useful: http://www.javaworld.com/javaworld/j...javatip34.html
The guy there said that the HTTP request's "content-type" field to be "application/x-www-form-urlencoded" because it is necessary since some versions of Netscape's browser has a bug which does not give out this proper content type when doing POSTs.

I think it would have been better if I just read in the xml request from a file - that's what I think I'll try to do now Oh and the URL: http://localhost:8080/52nSOSv2/sos specifies the URL to the servlet as defined in the web.xml of any servlet driven website.
Last edited by PoovenM; Jan 9th, 2008 at 3:09 am.
Reputation Points: 56
Solved Threads: 11
Junior Poster
PoovenM is offline Offline
147 posts
since Aug 2006

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in RSS, Web Services and SOAP Forum Timeline: Output XML from a servlet
Next Thread in RSS, Web Services and SOAP Forum Timeline: View an xml file in ie





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC