Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

If you use AXIS for Web Services then..

843833May 18 2005 — edited May 18 2005
I have been working on a Web Service the last 2 weeks and finally got a connection working with JAVA and AXIS. The question I have is this. First off, my code listed below is so very simple and it works. Now all the so called examples that I have seen out there seem to have the code replicated from the SoapBindingStub file and if I try to duplicate the way that they have there code, I can not get it to work.

At the end of this file is a sample of what I have seen others posting. So what all should be in my client to communicate with the stubs of the Service?

Why would the others be so redundant by putting code from the soapbindingstub into a client?


/////////////////////////////////////////////////////////////////////////////////////////
Assuming you already have a web service deployed.
You have gotten a wsdl.
You have ran WSDL2Java on the wsdl

Your client would look like the following.
/////////////////////////////////////////////////////////////////////////////////////////
import folderPathToWSDL2JavaGeneratedFolder.*;

public class MyClientCallerToWebServiceX {

   public static void main(String[] args) throws Exception {
               // create an instance of our service locator
         MyWebServicesServiceLocator locator = new MyWebServicesServiceLocator();

               // create an instance or our SoapBindingStub
         MyWebServicesSoapBindingStub stub = (MyWebServicesSoapBindingStub) locator.getMyWebServices();

               // make a call to a method we created in our web service
       System.out.println("Data on server: " + (stub.getSomeMethodOfMine("pass in a value").toString()));
 }
}
////////////////////////////////////////////////


Others type of coding........
import org.apache.axis.attachments.AttachmentPart;
import org.apache.axis.attachments.Attachments;
import org.apache.axis.client.Call;
import org.apache.axis.message.SOAPHeaderElement;
import org.apache.axis.message.*;
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import java.io.*;
import javax.xml.namespace.QName;
import org.apache.axis.encoding.XMLType;
import javax.xml.rpc.ParameterMode;
import org.apache.axis.encoding.ser.JAFDataHandlerDeserializerFactory;
import org.apache.axis.encoding.ser.JAFDataHandlerSerializerFactory;

public class NC
{
public static void main(String [] args)
{
try
{
Call call = new Call("web service address");

//insert session id into header
SOAPHeaderElement header = new SOAPHeaderElement("http://xml.apache.org/axis/session", "sessionID", 575757);

call.addHeader(header);


//testing attachment stuff
DataHandler dh = new DataHandler(new FileDataSource(""));

QName qnameAttachment = new QName("NescaumReport", "DataHandler");

call.registerTypeMapping(dh.getClass(), //Add serializer for attachment.
qnameAttachment,
JAFDataHandlerSerializerFactory.class,
JAFDataHandlerDeserializerFactory.class);

call.addParameter("iID", XMLType.XSD_INT,
ParameterMode.IN);
call.addParameter("startDate", XMLType.XSD_STRING,
ParameterMode.IN);
call.addParameter("endDate", XMLType.XSD_STRING,
ParameterMode.IN);

//Add the filename.


call.setReturnType(qnameAttachment);


Object ret = call.invoke("", "generateData", new Object[] {new Integer(21),"11/11/2004", "11/12/2004"});

}
catch (Exception e)
{
System.err.println("Error : " + e.toString());
}
}
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 15 2005
Added on May 18 2005
2 comments
277 views