• Entries (RSS)
  • Comments (RSS)

Invoking a web service using web service proxy client

Posted by | Posted in Web service, WebSphere | Posted on 15-09-2008

Tagged Under : , , ,

Invoking a web service using web service proxy client

Yesterday I got a comment on my post “Generating a web service proxy client” asking how do we invoke or test this web service using the webservice proxy client. So I thought of writing a post of how to use the generated proxy client to call a webservice. Here I am going to create a simple JSP file that is going to use the webservice proxy client to call or invoke the Hello World web service running in WebSphere.

Before you start, please make sure that you have generated the web service client as mentioned in Generate web service proxy client in java. If you do not have the Hello World web service running in your server, follow the tutorial at Creating a Hello World web service using RAD.

While generating the webservice proxy client I generated the Java files using no wrapped style.

One we have the java proxy files generated we can see some files named XXXProxy.java, XXX.java, XXXService.java, XXXServiceInformation.java, XXXServiceLocator.java etc in our workspace. Now create a new jsp file for calling the web service. Add the following code to invoke the Hello World webservice using our web service proxy client.

	com.test.HelloWorldProxy proxy = new com.test.HelloWorldProxy();
        proxy.setEndpoint("http://localhost:9081/WSTest/services/HelloWorld");
        String name = proxy.sayHello("Albin Joseph");
 
        System.out.println(name);

If everything works fine, we would see a ‘Hello Albin Joseph’ as the output in your console.

Our Hello World service was exposing a sayHello method as a webservice. The HelloWorldProxy class is the proxy client class for our webservice. If we are not setting the end point url (the url of the webservice), our proxy client would take the default one present in the wsdl file.

Share

Read More

Comments

37 comments posted onInvoking a web service using web service proxy client

  1. Thanks Buddy, it worked for me. :grin:

    The way you explaned the example is awesome any one who is new to web service can understand
    it easily. This is really good POC before start working on Web service. I really appriciate that

    Thanks again for your help.

  2. Thanks Amit.

  3. Hey, Though I am able to get the response back from my service provider, some message is displayed on console while using proxy to access ws. I am not able to findout why this is thrown. message displayed is:

    [9/21/08 19:41:52:027 PDT] 0000002d javaURLContex E NMSV0310E: A JNDI operation on a “java:” name cannot be completed because the server runtime is not able to associate the operation’s thread with any J2EE application component. This condition can occur when the JNDI client using the “java:” name is not executed on the thread of a server application request. Make sure that a J2EE application does not execute JNDI operations on “java:” names within static code blocks or in threads created by that J2EE application. Such code does not necessarily run on the thread of a server application request and therefore is not supported by JNDI operations on “java:” names. Exception stack trace:
    javax.naming.ConfigurationException [Root exception is javax.naming.NameNotFoundException: Name comp/env/service not found in context "java:".]
    at com.ibm.ws.naming.java.javaURLContextImpl.throwConfigurationExceptionWithDefaultJavaNS(javaURLContextImpl.java:411)
    at com.ibm.ws.naming.java.javaURLContextImpl.lookup(javaURLContextImpl.java:388)
    at com.ibm.ws.naming.java.javaURLContextRoot.lookup(javaURLContextRoot.java:204)
    at com.ibm.ws.naming.java.javaURLContextRoot.lookup(javaURLContextRoot.java:144)
    at javax.naming.InitialContext.lookup(InitialContext.java:363)

    Please help….

  4. Hi,

    Please send the complete execurise to me.

    regards
    ram

  5. @ram, Can’t you follow the steps mentioned in this post? Are you too lazy ?

  6. We generated a JSP from RAS… our problem is that the Result is a string created by … introspector.visit. Can you suggest a better way to intercept the result and format as XML?

  7. Can you please provide an tutorial on how to consume mtlm secured sharepoint web service in RAD 7.
    I am getting error 401.2 while consuming.

  8. i have this problem…

    24-Apr-2009 19.18.30 com.ibm.ws.naming.java.javaURLContextFactory
    SEVERE: javaAccessorNotSet
    namingException: javax.naming.ConfigurationException: Name space accessor for the java: name space has not been set. Possible cause is that the user is specifying a java: URL name in a JNDI Context method call but is not running in a J2EE client or server environment.

    i have a error when call the look up
    __helloWorld = ((HelloWorldService)ctx.lookup(“java:comp/env/service/HelloWorldService”)).getHelloWorld();

    for call this service i don’t use a jsp, but a main class in the web servise project, could be a problem ? booooo…

    help me please…

  9. Hi,
    I am facing the same issue.
    Can you please tell me how you resolved it in?

    Thanks
    Gaurav

  10. Hi , I am getting following error when i try invoke service from client class
    Sep 11, 2009 11:06:51 AM com.ibm.ws.naming.java.javaURLContextFactory
    SEVERE: javaAccessorNotSet
    Exception in thread “main” java.lang.NoClassDefFoundError: org.eclipse.core.runtime.CoreException
    at java.lang.J9VMInternals.verifyImpl(Native Method)
    at java.lang.J9VMInternals.verify(J9VMInternals.java:59)
    at java.lang.J9VMInternals.initialize(J9VMInternals.java:120)
    at com.ibm.ws.webservices.multiprotocol.discovery.ServiceProviderManager.getDiscoveredServiceProviders(ServiceProviderManager.java:378)
    at com.ibm.ws.webservices.multiprotocol.discovery.ServiceProviderManager.getAllServiceProviders(ServiceProviderManager.java:214)
    at com.ibm.ws.webservices.multiprotocol.discovery.ServiceProviderManager.getSupportingServiceProvider(ServiceProviderManager.java:400)
    at com.ibm.ws.webservices.multiprotocol.discovery.ServiceProviderManager.getServiceProvider(ServiceProviderManager.java:241)
    at com.ibm.ws.webservices.multiprotocol.utils.ServiceManager.discoverServiceForNamespace(ServiceManager.java:167)
    at com.ibm.ws.webservices.multiprotocol.utils.ServiceManager.getServiceForNamespace(ServiceManager.java:103)
    at com.ibm.ws.webservices.multiprotocol.AgnosticService.getGeneratedStub(AgnosticService.java:525)
    at com.ibm.ws.webservices.multiprotocol.AgnosticService.doGetPort(AgnosticService.java:462)
    at com.ibm.ws.webservices.multiprotocol.AgnosticService.getStub(AgnosticService.java:405)
    at com.test.HelloWorldServiceLocator.getHelloWorld(HelloWorldServiceLocator.java:68)
    at com.test.HelloWorldServiceLocator.getHelloWorld(HelloWorldServiceLocator.java:63)
    at com.test.HelloWorldProxy._initHelloWorldProxy(HelloWorldProxy.java:24)
    at com.test.HelloWorldProxy.(HelloWorldProxy.java:9)
    at com.test.Test.main(Test.java:13)

    Here is my client class
    public class Test {

    /**
    * @param args
    */
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    try {
    System.out.println(“HEEEEEEEEE”);
    com.test.HelloWorldProxy proxy = new com.test.HelloWorldProxy();
    proxy.setEndpoint(“http://localhost:9080/WebFncc/services/HelloWorld”);
    String name = proxy.sayHello(“Albin Joseph”);

    System.out.println(name);
    } catch (RemoteException e)
    {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }

    }

    }

  11. Hi,

    I’m also getting the same below problem.

    Please let me know if any updates.

    Sep 22, 2009 9:34:04 AM com.ibm.ws.naming.java.javaURLContextFactory
    SEVERE: javaAccessorNotSet
    Exception in thread “main” java.lang.NoClassDefFoundError: org.eclipse.core.runtime.CoreException
    at java.lang.J9VMInternals.verifyImpl(Native Method)
    at java.lang.J9VMInternals.verify(J9VMInternals.java:66)
    at java.lang.J9VMInternals.initialize(J9VMInternals.java:127)
    at com.ibm.ws.webservices.multiprotocol.discovery.ServiceProviderManager.getDiscoveredServiceProviders(ServiceProviderManager.java:378)
    at com.ibm.ws.webservices.multiprotocol.discovery.ServiceProviderManager.getAllServiceProviders(ServiceProviderManager.java:214)
    at com.ibm.ws.webservices.multiprotocol.discovery.ServiceProviderManager.getSupportingServiceProvider(ServiceProviderManager.java:400)
    at com.ibm.ws.webservices.multiprotocol.discovery.ServiceProviderManager.getServiceProvider(ServiceProviderManager.java:241)
    at com.ibm.ws.webservices.multiprotocol.utils.ServiceManager.discoverServiceForNamespace(ServiceManager.java:167)
    at com.ibm.ws.webservices.multiprotocol.utils.ServiceManager.getServiceForNamespace(ServiceManager.java:103)
    at com.ibm.ws.webservices.multiprotocol.AgnosticService.getGeneratedStub(AgnosticService.java:558)
    at com.ibm.ws.webservices.multiprotocol.AgnosticService.doGetPort(AgnosticService.java:491)
    at com.ibm.ws.webservices.multiprotocol.AgnosticService.getStub(AgnosticService.java:434)

  12. @nkr, netra. I have not faced this problem. However Google says that adding com.ibm.ws.webservices.thinclient_6.1.0.jar file in your classpath would resolve this issue. This file will be present in your %RAD_HOME%\runtimes\ \runtimes folder. Hope this helps.

  13. Hi Albin,

    When we give this link in browser i am getting “Hi there, this is a Web service!”……. here is my URL(https://localhost:10035/TestDemoPOCWeb/services/ConnectLibrary) …… the same as yours (http://localhost:9081/WSTest/services/HelloWorld).. But what the client expects is he should get the link for downloading the wsdl file and he can access from their side.. please help me regarding this,, as this is very urgent…

    Thanks in advance.

  14. I think if you will append ?wsdl to your url, you will be able to see the wsdl of your web service.

  15. Thanks a lot ,,, it helped me a lot

  16. :o Too Good example….. your posts always helps me……

  17. Hi albin,

    Thanks a lot for your posts..When i have seen the link that is generated from wsdl file ,, it was like https://localhost:10035/TestDemoPOCWeb/services/ConnectLibrary but ur URL is like http://localhost:9081/WSTest/services/HelloWorld… i 2 dont want that https to come into my url.. What should i do for it?

  18. Edit your WSDL and change the soap address. That will work.

  19. Hi Albin,

    When i changed that link from https to http it is giving as 5 square boxes as this “ “…

    If it is in https and if i try to access it from other machine ,, will i get ant security exceptions as “ssl configurations exception” etc….because i have tried it in my system .. it has worked.. now i am going to client place to give the demonstration…

  20. Browser will give ssl exception if your certificate is not trusted(usually that will be the case for all the servers except production). Anyway you can just trust the certificate and it will work :-)

  21. I forgot to say one thing. If you change the protocol to http you need to change the port also. the port for http and https are different.

  22. “trust the certificate” means when we run it via internetexplorer it gives option yes no and view certificate,, so if we click on yes,, will it work from other system also. the same i am clicking from my own system,,,

    Please dont mind.. i am just worried,, if it works properly or not :grin:

  23. yeah just say yes in IE and it will work from any systems.

  24. https://localhost:10035/TestDemoPOCWeb/services/ConnectLibrary ,, here the port for https is 10035…then wt will be the port for http??.. Is this the port address u r mentioning?

  25. Thanks a lot for your information :smile:

  26. https://localhost:10035/TestDemoPOCWeb/services/ConnectLibrary ,, here the port for https is 10035…In the previous post u said that there will be different port address for http.. Can u please provide the port address for HTTP ,,as my webservices port is giving as 10035. Actually i am not understanding wy the webservices has generated https? can u please help me in this issue…Because client is asking us to deploy it in production server, in which u have mentioned it will throw ssl exceptions,, I am using webservices version 6.1 Portal and RAD 7.5

  27. To get the http port associated login to your admin console and navigate to the following location. Server – Application Servers – Server1 – ports (under communications ) configuration. Find out the value of the WC_defaulthost. This will be the your http port. Http port will be under WC_defaulthost_secure.

  28. Hi Albin,

    I have tested with both the ports as u said under port configurations , port given under WC_defaulthost is 10000 and port given under WC_defaulthost_secure is 10002,, i have tried with both the links http://localhost:10002/finalValPOCWeb/services/ConnectLibrary and http://localhost:10000/finalValPOCWeb/services/ConnectLibrary… i also edited these port nubers in my soap address in wsdl file that is generated…. I am getting page cannot be displyed.. can u please help me.. Thanks in advance

  29. Hi Albin,

    I have tested with Server – Application Servers – Websphere Portal – ports (under communications ) configuration,, It was found to be 10040 and i gave teh same in esdl file… It is working….. with http port.. thank you albin for your support ,, keep it up :smile:

  30. Hi Albin,

    Today i have gone for the demo..There client is asking for the methods should get displayed when he gives webservices link in IE.Here is my URL..http://localhost:10040/validFinalNewWeb/services/MdrService .. In this URL i have 7 methods named getMetadata() , getUpdatedMetadata() , etc.. So as soon as this url hits in IE , we should be in a position to show these methods..Can u please help me how to show these methods in IE?,, Thank you

  31. Hey Sunil,

    I don’t think you will bw able to do that in a simple way just hitting the url of the service. You will have to develop some custom GUI for the same in which you will have to parse the wsdl file for getting all the operations(methods) specified and then display it as you want.

  32. Thanks for the reply Gaurav,
    Can u please guide me in parsing that wsdl file,, Because without this we are not able to satisfy client requirements.. Do u have any sample code for that ? Thanks in advance

  33. You are awasome..thanks. I have faced this problem and your resolution works for me…gr8*****

  34. What is the different between the service locator generated by axis vs this ibm proxy class

  35. Hi Albin….first of all i am saying thanx to u for providing knowledge on web services through your tutorials.. i am using rad 7.5,the steps which u have mentioned in this tutorial differs slightly in rad 7.5..can u assist me how to go through rad 7.5 for this example……plz give me reply…

  36. The steps will be almost same with some minor changes. So if you follow this tutorial, it should work for almost all the RAD versions with some minor differences.

  37. Hello,
    I have a webserivce, to access this service from another J2EE application ( web ) , I’m including serviceInfo.xml and the client.jar of webserivce.
    In this serviceInfo.xml I’m providing the JNDI.
    which had been configured on WAS.

    But at run time, calling the service through consumer application I’m getting below error,

    javax.naming.NameNotFoundException: Name comp/env/service not found in context “java:”.

    I’m able to access webservice through soapUI application / and stand alone java application by proving the direct URL.

    Any help / input for above error ?

Post a Comment