• 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

Need to invoke SOAP msg with standalone java class

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI
can any one help me out to slove this problem.
I need to invoke a webservice
i have a wsdl file Stockquotes.wsdl file
based on this i have constructed an input SOAP msg
like this
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://www.webserviceX.NET/">
<soapenv:Header/>
<soapenv:Body>
<web:GetQuote>
<!--Optional:-->
<web:symbol>GOOG</web:symbol>
</web:GetQuote>
</soapenv:Body>
</soapenv:Envelope>

from java i will construct a String with this SOAP.

now my Doubt is how to send this SOAP msg to hit that wsdl and to get responce.
please address me how to create a stand alone java class with this soap msg to get the responce.

Mortin.
 
Ranch Hand
Posts: 959
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Normally you will need to create a stub from that WSDL. If you have the stub, you don't need to worry about creating the SOAP message manually as well as creating a socket.

If you prefer to build the SOAP message manually, you can use SAAJ and invoke SOAPConnection.call(SOAPMessage request, Object to).

Which web service stack do you use by the way?
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you have a complete template for the SOAP message there is no need to build a SOAP client. See the HttpURLConnection in java.net package for how to POST a message to the service.

I did this for a client who didn't want to get all tangled up in SOAP toolkits. It can be very simple if the SOAP response is not too complex and is MUCH faster than building a SOAP request from scratch. SOAP is just about messaging - no need to get more complex than you have to.

Bill
 
Mortin kim
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI here is the class I writen,i am able to get the connection and constructed SOAP msg too this is publically available webservice can you please tell how to proceed further..it will great help.

import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
public class TestClient {
public static void main(String [] args) {
try {
// Construct data

String soapMsg = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:web="+"http://www.webserviceX.NET/\">";
st1 = st1 +"<soapenv:Header/> <soapenv:Body> <web:GetQuote> <web:symbol>"+"GOOG"+"</web:symbol> </web:GetQuote> </soapenv:Body> </soapenv:Envelope>";

String data = URLEncoder.encode(soapMsg, "UTF-8");
// Send data
URL url = new URL("http://www.webservicex.net/stockquote.asmx?wsdl");
URLConnection conn = url.openConnection();
System.out.println("Url Connection "+conn);
 
Freddy Wong
Ranch Hand
Posts: 959
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From the URLConnection class, use getOutputStream() to get the OutputStream to write your request data.
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to do a bit more with the HttpURLConnection. Here is the complete method I used.


It is important to note that if the URL starts "http://" you get a HttpURLConnection - an extension of URLConnection with methods specific to HTTp.
Bill
[ July 01, 2008: Message edited by: William Brogden ]
 
I'm sure glad that he's gone. Now I can read this tiny ad in peace!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic