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.ServiceFacto ry;
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.ServiceFact ory", "com.sun.xml.rpc.client.Se rviceFacto ryImpl");
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.sto ckquote.St ockQuoteSe rvice");
QName portName = new QName(targetNamespace, "net.xmethods.services.sto ckquote.St ockQuotePo rt");
QName operationName = new QName("urn:xmethods-delaye d-quotes", "getQuote");
// create service
Service service = factory.createService(wsdl Location, serviceName);
// create call
Call call = service.createCall(portNam e, operationName);
// invoke the remote web service
Float result = (Float) call.invoke(new Object[] {"BEAS"});
System.out.println(result) ;
}
}
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.ServiceFacto
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.ServiceFact
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.sto
QName portName = new QName(targetNamespace, "net.xmethods.services.sto
QName operationName = new QName("urn:xmethods-delaye
// create service
Service service = factory.createService(wsdl
// create call
Call call = service.createCall(portNam
// invoke the remote web service
Float result = (Float) call.invoke(new Object[] {"BEAS"});
System.out.println(result)
}
}
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".
ASKER
Have an error on "create service" line.
did you run the above code?
did you run the above code?
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..
ASKER
is there any other function instead invoke?
I need to get a return value from web service server based on WSDL.
I need to get a return value from web service server based on WSDL.
your service is working. use axis to call this;
NetXmethodsServicesStockqu oteStockQu oteService service = new NetXmethodsServicesStockqu oteStockQu oteService Locator();
try {
NetXmethodsServicesStockqu oteStockQu otePortTyp e call = service.getNetXmethodsServ icesStockq uoteStockQ uotePort() ;
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
NetXmethodsServicesStockqu
try {
NetXmethodsServicesStockqu
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
ASKER
NetXmethodsServicesStockqu oteStockQu oteService
what is it? where is this class defined..??
what is it? where is this class defined..??
ASKER
How did you axis? I did download axis-bin-1_4. where can i put this one?
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?
is it not a simple way?
do i have to use wsdl2java generator?
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?
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
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
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.WSDL2 Java -o %OUTPUT_DIR% -p %OUTPUT_PAC% -a -v -s xxxxxxxxxxxxxxxxx.wsdl
the command like this;
java -cp %MYCLASSPATH% org.apache.axis.wsdl.WSDL2
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.WSDL2 Java -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,,
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.WSDL2
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.WSDL2 Java -o . -d Session -s -p tempv1.ws http://soap.amazon.com/schemas2/AmazonWebServices.wsdl
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.WSDL2
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.SAXParse rFactory ) at an unknown location
Found Activation API ( javax.activation.DataHandl er ) at an unknown location
what does this message mean?
Found SAAJ API ( javax.xml.soap.SOAPMessage
Found JAXP implementation ( javax.xml.parsers.SAXParse
Found Activation API ( javax.activation.DataHandl
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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\l
3. I set all jar in classpath using "environment variables"
4. run cmd
5. c:\>java org.apache.axis.wsdl.WSDL2
6. will it be create .java ??
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
6. will it be create .java ??
yes it will do that :)
yes it will do that :)
ASKER
I have this error:
Exception in thread "main" java.lang.NoClassDefFoundE rror: org/apache/axis/wsdl/WSDL2 java
Exception in thread "main" java.lang.NoClassDefFoundE
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>
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.NoClassDefFoundE rror: org/apache/axis/wsdl/WSDL2 java
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.
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.
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-dis covery-0.2 .jar;
C:\Program Files\axis_lib\commons-log ging-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.ja r;
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.WSDL2 Java -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.NoClassDefFoundE rror: org/apache/axis/wsdl/WSDL2 java
did I miss something?
--------------------------
C:\Program Files\axis_lib\axis.jar;
C:\Program Files\axis_lib\commons-dis
C:\Program Files\axis_lib\commons-log
C:\Program Files\axis_lib\jaxrpc.jar;
C:\Program Files\axis_lib\saaj.jar;
C:\Program Files\axis_lib\log4j-1.2.8
C:\Program Files\axis_lib\xml-apis.ja
C:\Program Files\axis_lib\xercesImpl.
C:\Program Files\axis_lib\wsdl4j-1.5.
--------------------------
INTO the bin directory.
And I typed the below
c:\>java org.apache.axis.wsdl.WSDL2
But it still gives me an error
Exception in thread "main" java.lang.NoClassDefFoundE
did I miss something?
use my directory sturcture i posted above.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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---
NetXmethodsServicesStockqu oteStockQu oteService service = new NetXmethodsServicesStockqu oteStockQu oteService Locator();
try {
NetXmethodsServicesStockqu oteStockQu otePortTyp e call = service.getNetXmethodsServ icesStockq uoteStockQ uotePort() ;
float f = call.getQuote("BEAS");
System.out.println(f);
} catch (Exception e) {
e.printStackTrace();
}
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---
NetXmethodsServicesStockqu
try {
NetXmethodsServicesStockqu
float f = call.getQuote("BEAS");
System.out.println(f);
} catch (Exception e) {
e.printStackTrace();
}
ASKER
java files..
----------
TestWS.java
TestWSBindingImpl.java
TestWSBindingStub.java
TestWSLocator.java
TestWSPortType.java
--------------
----------
TestWS.java
TestWSBindingImpl.java
TestWSBindingStub.java
TestWSLocator.java
TestWSPortType.java
--------------
ASKER
do i need to run java file first to make class file?
ASKER
will it be generated java class also?
ASKER
I mean class file...
well....I cannot see java.io.Serializable..
well....I cannot see java.io.Serializable..
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.
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.
look at here...
http://dev.kanngard.net/Permalinks/ID_20050526165433.html
http://ws.apache.org/axis/java/user-guide.html
http://www.onjava.com/pub/a/onjava/2002/06/05/axis.html
http://www.onjava.com/pub/a/onjava/2002/06/05/axis.html?page=2
http://www.ibm.com/developerworks/webservices/library/ws-castor/
http://www-128.ibm.com/developerworks/java/library/os-ag-axis2mig/index.html
R.K
http://dev.kanngard.net/Permalinks/ID_20050526165433.html
http://ws.apache.org/axis/java/user-guide.html
http://www.onjava.com/pub/a/onjava/2002/06/05/axis.html
http://www.onjava.com/pub/a/onjava/2002/06/05/axis.html?page=2
http://www.ibm.com/developerworks/webservices/library/ws-castor/
http://www-128.ibm.com/developerworks/java/library/os-ag-axis2mig/index.html
R.K
ASKER
It is working now.
Thanks.
Thanks.