Link to home
Start Free TrialLog in
Avatar of bbvic
bbvic

asked on

web service

I am working on web service client.
the below code was copied and a little bit changed.
But this code does not work..
Woudl you please help how i can solve this


    import java.net.URL;

    import javax.xml.rpc.ServiceFactory;
    import javax.xml.rpc.Service;
    import javax.xml.rpc.Call;
   
    import javax.xml.namespace.QName;

    public class Main {

      public static void main(String[] args) throws Exception {

        System.setProperty( "javax.xml.rpc.ServiceFactory", "com.sun.xml.rpc.client.ServiceFactoryImpl");
        ServiceFactory factory = ServiceFactory.newInstance();
        URL wsdlLocation = new URL("http://services.xmethods.net/soap/urn:xmethods-delayed-quotes.wsdl");
       
        String targetNamespace = "http://www.themindelectric.com/wsdl/net.xmethods.services.stockquote.StockQuote/";
        QName serviceName = new QName(targetNamespace, "net.xmethods.services.stockquote.StockQuoteService");
        QName portName = new QName(targetNamespace, "net.xmethods.services.stockquote.StockQuotePort");
        QName operationName = new QName("urn:xmethods-delayed-quotes", "getQuote");

        // create service
        Service service = factory.createService(wsdlLocation, serviceName);
        // create call
        Call call = service.createCall(portName, operationName);
        // invoke the remote web service
        Float result = (Float) call.invoke(new Object[] {"BEAS"});
        System.out.println(result);
     
      }

    }
Avatar of Siva Prasanna Kumar
Siva Prasanna Kumar
Flag of India image

What error are u getting? I think that webservice is down as i am getting a Connection timed out. only the WSDL is present at Xmethods i tryed invoking it But it says "Connection timed Out".
Avatar of bbvic
bbvic

ASKER

Have an error on "create service" line.

did you run the above code?
Avatar of bbvic

ASKER

when it compiles the above java code,  the it gets an error on the below "create service" comment.
no man i used AXIS client :) which is a java based client i use eclipse to generate the client..
Avatar of bbvic

ASKER

is there any other function instead invoke?
I need to get a return value from web service server based on WSDL.
your service is working. use axis to call this;

NetXmethodsServicesStockquoteStockQuoteService service = new NetXmethodsServicesStockquoteStockQuoteServiceLocator();
try {
      NetXmethodsServicesStockquoteStockQuotePortType call = service.getNetXmethodsServicesStockquoteStockQuotePort();                  
      float f = call.getQuote("BEAS");
      System.out.println(f);                  
} catch (Exception e) {
      e.printStackTrace();
}             


for more info;
http://ws.apache.org/axis/java/user-guide.html
Avatar of bbvic

ASKER

NetXmethodsServicesStockquoteStockQuoteService

what is it? where is this class defined..??
Avatar of bbvic

ASKER

How did you axis? I did download axis-bin-1_4. where can i put this one?
Avatar of bbvic

ASKER

is there any way to modify using the orginal code, not using axis?
 is it not a simple way?
do i have to use wsdl2java generator?

Avatar of bbvic

ASKER

In fact, I am using NetBeans IDE 5.5 and there is a function to generate web service client from WSDL.

but it does not create a client side and it has some errors..

Has anyone used NetBeans to generate web service client?
>>what is it? where is this class defined..??
generate related class by wsdl2java

>>How did you axis? I did download axis-bin-1_4. where can i put this one?
you need some jars which comes with axis; axis.jar, jaxrpc.jar, commons-logging.jar, commons-discovery.jar, saaj.jar, wsdl4j.jar

for more info;
http://ws.apache.org/axis/java/user-guide.html

>>is there any way to modify using the orginal code, not using axis?
i dont know but it very is by axis. i call your webservice successfully by axis.

i am using eclipse :( but it runs at every IDE
I tryed using Netbeans it says"error: rpc/encoded wsdls are not supported in JAXWS 2.0."

Than means you can't use Netbeans for generating code for this WSDL the only way to go is use AXIS 2 wsdl 2 java its and eclipse plugin easy to use.

see this

http://ws.apache.org/axis2/tools/1_2/eclipse/wsdl2java-plugin.html
I usually modify my batch file which creates javas from wsdl to where i speficed output directory then i move these files to my project. so i is very easy and IDE independent ;)

the command like this;
java -cp %MYCLASSPATH% org.apache.axis.wsdl.WSDL2Java -o %OUTPUT_DIR% -p %OUTPUT_PAC% -a -v -s xxxxxxxxxxxxxxxxx.wsdl
Avatar of bbvic

ASKER

ok.....axis and tomcat installation were succeed.

Then how to use the tool for wsdl2java?

here is wsdl location, for example,...

http://soap.amazon.com/schemas2/AmazonWebServices.wsdl

is this rignt command?

java org.apache.axis.wsdl.WSDL2Java -o . -d Session -s -p tempv1.ws http://soap.amazon.com/schemas2/AmazonWebServices.wsdl

after it creates java files, where those will be saved?

Thanks,,


Ya that command seems fine  any way for running WSDL2java sucessfully u need to have eight jars in the class path they are

axis.jar, saaj.jar, jaxrpc..jar, and so on do one thing put all the jar files in that axis lib folder in class path before running the below command.

java org.apache.axis.wsdl.WSDL2Java -o . -d Session -s -p tempv1.ws http://soap.amazon.com/schemas2/AmazonWebServices.wsdl
Avatar of bbvic

ASKER

well..I have this message when it opens http://127.0.0.1:8080/axis/happyaxis.jsp

Found SAAJ API ( javax.xml.soap.SOAPMessage ) at an unknown location
Found JAXP implementation ( javax.xml.parsers.SAXParserFactory ) at an unknown location
Found Activation API ( javax.activation.DataHandler ) at an unknown location

what does this message mean?
this means yur SAAJ.jar is still not in classpath or is not loaded. Do u have weblogic installed in your system? then u need to do lot more.
Avatar of bbvic

ASKER

weblogic? what version and what should i download from there?
no don't download any thing else :) just set the saaj.jar in classpath
SOLUTION
Avatar of Siva Prasanna Kumar
Siva Prasanna Kumar
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bbvic

ASKER


1. Tomcat.

C:\Program Files\Apache Software Foundation\Tomcat 5.5\common\lib

2. axis

C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\axis\WEB-INF\lib

3. I set all jar in classpath using "environment variables"

4. run cmd

5. c:\>java org.apache.axis.wsdl.WSDL2Java -o . -d Session -s -p tempv1.ws http://soap.amazon.com/schemas2/AmazonWebServices.wsdl

6. will it be create .java ??

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
6. will it be create .java ??

yes it will do that :)
Avatar of bbvic

ASKER

I have this error:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/axis/wsdl/WSDL2java
Avatar of bbvic

ASKER

In fact, I have this issue..

after testing a SOAP Endpoint, I have xml format like the below.
is this correct one??

<?xml version="1.0" encoding="UTF-8" ?>
<soapenv:Envelope">
  <soapenv:Body>
    <getVersionResponse
     soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
      <getVersionReturn
       xsi:type="xsd:string">
         Apache Axis version: 1.4 Built on Apr 22, 2006 (06:55:48 PDT)
      </getVersionReturn>
    </getVersionResponse>
  </soapenv:Body>
</soapenv:Envelope>


------------------- based on instruction -----------------------------

<?xml version="1.0" encoding="UTF-8" ?>
<soapenv:Envelope
 xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <soapenv:Body>
    <getVersionResponse
     soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
      <getVersionReturn
       xsi:type="xsd:string">
         Apache Axis version: 1.1 Built on Apr 04, 2003 (01:30:37 PST)
      </getVersionReturn>
    </getVersionResponse>
  </soapenv:Body>
</soapenv:Envelope>
i am not getting why are u trying to invoke the default version web service which comes with axis.???
>>> Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/axis/wsdl/WSDL2java

are the jar files in class path???  its not able to find that class file that means the axis.jar may not be in the class path.
Avatar of bbvic

ASKER

I add full path name: c:\jdk1.5.0_06\bin and added the required .jar files
-----------------------------------------------
C:\Program Files\axis_lib\axis.jar;
C:\Program Files\axis_lib\commons-discovery-0.2.jar;
C:\Program Files\axis_lib\commons-logging-1.0.4.jar;
C:\Program Files\axis_lib\jaxrpc.jar;
C:\Program Files\axis_lib\saaj.jar;
C:\Program Files\axis_lib\log4j-1.2.8.jar;
C:\Program Files\axis_lib\xml-apis.jar;
C:\Program Files\axis_lib\xercesImpl.jar;
C:\Program Files\axis_lib\wsdl4j-1.5.1.jar;
-------------------------------------------------
INTO  the bin directory.


And I typed the below

c:\>java org.apache.axis.wsdl.WSDL2Java -o D:\temp\ws -d Session -s -p tempv1.ws http://soap.amazon.com/schemas2/AmazonWebServices.wsdl

But it still gives me an error
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/axis/wsdl/WSDL2java

did I miss something?
use my directory sturcture i posted above.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bbvic

ASKER

It creates the needed java files..
then..how to get a value through the web service..

can you show how to do it? such as including import, public, and so on..

---sample that i have---
NetXmethodsServicesStockquoteStockQuoteService service = new NetXmethodsServicesStockquoteStockQuoteServiceLocator();
try {
      NetXmethodsServicesStockquoteStockQuotePortType call = service.getNetXmethodsServicesStockquoteStockQuotePort();                  
      float f = call.getQuote("BEAS");
      System.out.println(f);                  
} catch (Exception e) {
      e.printStackTrace();
}            



Avatar of bbvic

ASKER

java files..

----------

TestWS.java
TestWSBindingImpl.java
TestWSBindingStub.java
TestWSLocator.java
TestWSPortType.java

--------------
Avatar of bbvic

ASKER

do i need to run java file first to make class file?
Avatar of bbvic

ASKER

will it be generated java class also?
Avatar of bbvic

ASKER

I mean class file...

well....I cannot see java.io.Serializable..

Avatar of bbvic

ASKER

well...assume that i have all java files , then..how to use it??

Ok now you need to write your own client which uses these classes to call the operation you like to invoke.

So write a java class with main method in it and then create a object of type proxy which got generated ;) and invoke suitable operation.
Avatar of bbvic

ASKER

It is working now.
Thanks.