Forums Register Login

Consuming a web service using Java

+Pie Number of slices to send: Send
Hi,

I am completely new to web services. I have an assignment in which I have to consume a web service called SPIDeR through SOAP. I need to pass some data in an XML format and get the results back in an XML format. Is there a web tutorial wherein I can see how to consume web services in Java?

Please help.

Thanks,
-Shruti
+Pie Number of slices to send: Send
In simple words, you need to write program (Java Web Service), then you need to deploy it on server - this is called server-side (server - which serves the request)
you need to write a program which will call (consume) your other Java program (Java web service) - this is call client-side (which makes a request to server)

p l s try following;
http://java.sun.com/developer/technicalArticles/J2SE/jax_ws_2/

after reading, you can download & install netbeans
http://netbeans.org/downloads/
and create a sample Java web service.
+Pie Number of slices to send: Send
Thank you so much for the reply!

I do not have to develop the web service. I just have to consume. SPIDeR is a web-based system. SPIDeR will return the results in an XML format. Also, there needs to be authentication/authorization done while making the web service call. How to pass the credentials while making a web service call?

Thanks,
-Shruti
+Pie Number of slices to send: Send
Hi Shruthi,
This link might help.
+Pie Number of slices to send: Send
Thanks, Naren!

I have one more question. The web service link I have is:
https://webapp.dss.state.va.us/SPIDERWeb/services/SearchMainWService?wsdl

Can I try directly accessing it (by pasting it in browser) or do I have to always call this link from the java code?

When I paste it directly in browser, it gives me a certificate error.

Thanks,
-Shruti
+Pie Number of slices to send: Send
That is a URI for the WSDL file for the web service. It is not the URI for the actual executable web service.

Web services are for two applications to communicate.

Humans can typically read a WSDL file in a browser for reference purposes, unless there are implemented security mechanisms to prevent this.
+Pie Number of slices to send: Send
OK, so how do I access the actual web service URL? If I remove the ?wsdl from https://webapp.dss.state.va.us/SPIDERWeb/services/SearchMainWService?wsdl and then try accessing the URL, then I get a certificate error saying 'Mismatched Address. The security certificate presented by this website was issued for a different website's address. This problem might indicate an attempt to fool you or intercept any data you send to the server.'

There should be a way to directly access this website as well through browser.

Here is how the wsdl looks:

*****************************

<?xml version="1.0" encoding="UTF-8" ?>
- <wsdl:definitions targetNamespace="http://webservices.spider.dss.org" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://webservices.spider.dss.org" xmlns:intf="http://webservices.spider.dss.org" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<wsdl:types />
- <wsdl:message name="executeSearchResponse">
<wsdl:part name="executeSearchReturn" type="xsd:string" />
</wsdl:message>
- <wsdl:message name="executeSSNSearchRequest">
<wsdl:part name="executeSSNSearch" type="xsd:string" />
</wsdl:message>
- <wsdl:message name="executeCaseNoSearchResponse">
<wsdl:part name="executeCaseNoSearchReturn" type="xsd:string" />
</wsdl:message>
- <wsdl:message name="executeSSNSearchResponse">
<wsdl:part name="executeSSNSearchReturn" type="xsd:string" />
</wsdl:message>
- <wsdl:message name="executeSearchRequest">
<wsdl:part name="executeSearch" type="xsd:string" />
</wsdl:message>
- <wsdl:message name="executeClientIDSearchResponse">
<wsdl:part name="executeClientIDSearchReturn" type="xsd:string" />
</wsdl:message>
- <wsdl:message name="executeCaseNoSearchRequest">
<wsdl:part name="executeCaseNoSearch" type="xsd:string" />
</wsdl:message>
- <wsdl:message name="executeClientIDSearchRequest">
<wsdl:part name="executeClientIDSearch" type="xsd:string" />
</wsdl:message>
- <wsdl:portType name="SearchMainWService">
- <wsdl:operation name="executeSearch" parameterOrder="executeSearch">
<wsdl:input message="impl:executeSearchRequest" name="executeSearchRequest" />
<wsdl:output message="impl:executeSearchResponse" name="executeSearchResponse" />
</wsdl:operation>
- <wsdl:operation name="executeSSNSearch" parameterOrder="executeSSNSearch">
<wsdl:input message="impl:executeSSNSearchRequest" name="executeSSNSearchRequest" />
<wsdl:output message="impl:executeSSNSearchResponse" name="executeSSNSearchResponse" />
</wsdl:operation>
- <wsdl:operation name="executeClientIDSearch" parameterOrder="executeClientIDSearch">
<wsdl:input message="impl:executeClientIDSearchRequest" name="executeClientIDSearchRequest" />
<wsdl:output message="impl:executeClientIDSearchResponse" name="executeClientIDSearchResponse" />
</wsdl:operation>
- <wsdl:operation name="executeCaseNoSearch" parameterOrder="executeCaseNoSearch">
<wsdl:input message="impl:executeCaseNoSearchRequest" name="executeCaseNoSearchRequest" />
<wsdl:output message="impl:executeCaseNoSearchResponse" name="executeCaseNoSearchResponse" />
</wsdl:operation>
</wsdl:portType>
- <wsdl:binding name="SearchMainWServiceSoapBinding" type="impl:SearchMainWService">
<wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />
- <wsdl:operation name="executeSearch">
<wsdlsoap:operation soapAction="" />
- <wsdl:input name="executeSearchRequest">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://webservices.spider.dss.org" use="encoded" />
</wsdl:input>
- <wsdl:output name="executeSearchResponse">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://webservices.spider.dss.org" use="encoded" />
</wsdl:output>
</wsdl:operation>
- <wsdl:operation name="executeSSNSearch">
<wsdlsoap:operation soapAction="" />
- <wsdl:input name="executeSSNSearchRequest">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://webservices.spider.dss.org" use="encoded" />
</wsdl:input>
- <wsdl:output name="executeSSNSearchResponse">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://webservices.spider.dss.org" use="encoded" />
</wsdl:output>
</wsdl:operation>
- <wsdl:operation name="executeClientIDSearch">
<wsdlsoap:operation soapAction="" />
- <wsdl:input name="executeClientIDSearchRequest">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://webservices.spider.dss.org" use="encoded" />
</wsdl:input>
- <wsdl:output name="executeClientIDSearchResponse">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://webservices.spider.dss.org" use="encoded" />
</wsdl:output>
</wsdl:operation>
- <wsdl:operation name="executeCaseNoSearch">
<wsdlsoap:operation soapAction="" />
- <wsdl:input name="executeCaseNoSearchRequest">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://webservices.spider.dss.org" use="encoded" />
</wsdl:input>
- <wsdl:output name="executeCaseNoSearchResponse">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://webservices.spider.dss.org" use="encoded" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
- <wsdl:service name="SearchMainWServiceService">
- <wsdl:port binding="impl:SearchMainWServiceSoapBinding" name="SearchMainWService">
<wsdlsoap:address location="https://surya9.dss.state.va.us/SPIDERWeb/services/SearchMainWService" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
*******************************************

Please give me some ideas on it.

Thanks,
-Shruti

+Pie Number of slices to send: Send
Hi Shruthi,

how do I access the actual web service URL?


The url for the web service is the end point address within WSDL. From your WSDL it is the location attribute


Usually, endpoint address followed by ?WSDL gives you WSDL of that web service but not always necessary. The WSDL can be elsewhere on the server and may have a different url.

Sometimes neither web service url nor its wsdl url can be directly accessed especially if they are available over secure transport protocol. Your application must prove it is a trusted caller through authentication or certificates. This is the reason why you couldn't access the urls directly in browser.
+Pie Number of slices to send: Send
 

OK, so how do I access the actual web service URL?



The details about using this service should be provided to authorized users from the owners of the service. This includes required security tokens, formats, and anything else needed (which only the authors know about.)

Since you are completely new to web services. Another answer to your question is, you access the web service URL by creating a properly written web service client application.


There should be a way to directly access this website as well through browser.



Not really. As I mentioned, a web service is for application-to-application communication. Humans entering a URL in a HTML-browser does not qualify as an "application." A web service client needs to be specifically created. Microsoft's Internet Explorer is not a web service client for example.

In regards to web service security, there are many, many options for implementing security. The publishers of a particular web service are typically the only source of security details about the service and how it is intented to be consumed.

A "web service" and a website are not the same thing.
+Pie Number of slices to send: Send
Thanks a lot Naren for such an elaborate explanation.

I believe that I need to create client using wsimport from JAX-WS. I need to pass the data to web service in XML format and get it back in XML format. How do I pass the XML file to web service? Is there a quick tutorial on that?

Thanks a lot for the answers.

-Shruti
+Pie Number of slices to send: Send
@Jimmy Clark:

The details about using this service should be provided to authorized users from the owners of the service


Humans can typically read a WSDL file in a browser for reference purposes, unless there are implemented security mechanisms to prevent this.


I am not sure why someone would create security mechanisms to prevent the viewing of a WSDL file. Especially since:
1) the intention of web services are to be located via public registries and
2) The WSDL just describes an interface. If the methods provided offer access to privileged operation some kind of runtime authentication would be created.
Could you please elaborate on your point and give a specific example? Because I have never thought/read of this before, i.e. restrict viewing of WSDL.
For example using annotations in java code WSDL is automatically generated and viewable by browser. Is the restriction of the viewing of WSDL configurable in the common case of annotating classes?

Thanks
+Pie Number of slices to send: Send
 

I am not sure why someone would create security mechanisms to prevent the viewing of a WSDL file. Especially since:
1) the intention of web services are to be located via public registries and



This is only partially accurate. There are many internal-only web service implementations alive in various commercial and government systems today.

To phrase your statement better, "the intention of some web services is to be used publicly."

+Pie Number of slices to send: Send
 

Jim Akmer wrote:I am not sure why someone would create security mechanisms to prevent the viewing of a WSDL file.


The less an attacker knows about what he's attacking, the harder is his task. That's why one suppresses unnecessary HTTP headers that give away the version of the server, for example.

the intention of web services are to be located via public registries and


No. Public registries have pretty much been a failure, not a single one worth mentioning remains in existence today. The only place where registries are still used are in some large companies for internal purposes.

Because I have never thought/read of this before, i.e. restrict viewing of WSDL.


With all due respect, then you haven't read much about security in the internet age. Start here: http://ws.apache.org/axis/java/security.html
+Pie Number of slices to send: Send
@Lester,Jimmy: Thank you for your comments. I will look into this more as you say. One last question though. In java the most frequent way to work with web services is using annotations. The WSDL is automatically generated by these annotations. In this case, how can the viewing of WSDL be restricted?

@Lester:

Public registries have pretty much been a failure, not a single one worth mentioning remains in existence today.


So what is the current replacement for registries in order to locate web services?
+Pie Number of slices to send: Send
 

Jim Akmer wrote:In java the most frequent way to work with web services is using annotations. The WSDL is automatically generated by these annotations. In this case, how can the viewing of WSDL be restricted?


That depends on the SOAP stack you're using. There may be a setting in the web.xml file of the underlying web app, or something similar. The documentation of the SOAP library in question should mention how to do it.

Jim Akmer wrote:

Public registries have pretty much been a failure, not a single one worth mentioning remains in existence today.


So what is the current replacement for registries in order to locate web services?



There isn't one. It was thought that a market place of publicly available commercial WS would emerge, and that registries would be used to locate one that fit your needs - but that never happened. These days, a company would make the WSDL available to authorized users so that you can build a client, but you'd have to come to know that the service exists by some other means (e.g., through a web search).
+Pie Number of slices to send: Send
Using Java annotations is one way to create SOAP-based web services. It is not the only way and is certainly not the best way. Either way, the creation of a WSDL file and the viewing of the file from a public browser are different things.

Web services are complex and there are still many aspects that have not matured, i.e. service registries.

In regards to public web services, many organizations do indeed make them available, e.g. Amazon.com, Ebay.com.
+Pie Number of slices to send: Send
This has been a real informative thread, especially on WS security. Thanks Jimmy & Lester.
I'm a lumberjack and I'm okay, I sleep all night and work all day. Lumberjack ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 44916 times.
Similar Threads
Web services overall picture and Jax-RPC
currency conversion
use of XML in the webservices
What is Web Service?
calling web service with input soap xml file
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 17:42:05.