aspose file tools*
The moose likes Web Services and the fly likes Need to invoke SOAP msg with standalone java class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "Need to invoke SOAP msg with standalone java class" Watch "Need to invoke SOAP msg with standalone java class" New topic
Author

Need to invoke SOAP msg with standalone java class

Mortin kim
Ranch Hand

Joined: Nov 15, 2007
Posts: 44
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.
Freddy Wong
Ranch Hand

Joined: Sep 11, 2006
Posts: 959

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?


SCJP 5.0, SCWCD 1.4, SCBCD 1.3, SCDJWS 1.4
My Blog
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12682
    
    5
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


Java Resources at www.wbrogden.com
Mortin kim
Ranch Hand

Joined: Nov 15, 2007
Posts: 44
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

Joined: Sep 11, 2006
Posts: 959

From the URLConnection class, use getOutputStream() to get the OutputStream to write your request data.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12682
    
    5
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 agree. Here's the link: http://aspose.com/file-tools
 
subject: Need to invoke SOAP msg with standalone java class
 
Similar Threads
How to make XML file from WebService responses?
Webservices and Websphere 5.1
Why Getting Fault Code in SOAP Response Message
sendind SOAP request
TcpMon in Eclipse