• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

how to invoke a webservice

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I need to know what needs to be done to invoke a web service? In other words what are the basics for writing a web service client?
Thanks
Ajay
 
author and deputy
Posts: 3150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Only few things,
  • Download Apache Axis
  • Read the documentation on using the pretty-tiny tool WSDL2Java

  • Its a tool which will automatically create the necessary java files (stubs)to for a given webservice(WSDL)

  • compile the java files, you can also import the necessary class to your application
  • run it.

  •  
    Ajay Chawla
    Greenhorn
    Posts: 11
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Thanks Balaji,
    Actually I need to do it without any tool.
    I've to use SOAP API. I think I can do it using Call().
    Can u tell me what I need to specify in Call.setTargetObjectURI()? is it the Web service name or some other identifier?
    Ajay
     
    Ajay Chawla
    Greenhorn
    Posts: 11
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Iam getting the following fault when i run my client : -
    faultcode :soap:Client
    faultString :Server did not recognize the value of HTTP Header SOAPAction:
    my code is : -
    Call call = new org.apache.soap.rpc.Call();
    URL url = new URL("http://delgtel304:7070/WebService2/JavaService1.asmx");
    call.setTargetObjectURI"http://delgtel304:7070/WebService2/JavaService1.asmx");
    call.setMethodName("JavaTest");
    call.setEncodingStyleURI(org.apache.soap.Constants.NS_URI_SOAP_ENC);
    Vector vParam = new Vector();
    vParam.addElement(new org.apache.soap.rpc.Parameter"str",String.class,"Ajay",null));
    call.setParams(vParam);
    org.apache.soap.rpc.Response resp = call.invoke(url, "");

    if(resp.generatedFault()){
    org.apache.soap.Fault fault = resp.getFault();
    System.out.println("faultcode :"+fault.getFaultCode());
    System.out.println("faultString :"+fault.getFaultString());
    }
    else{
    org.apache.soap.rpc.Parameter result = resp.getReturnValue();
    System.out.println(result.getValue());
    }
    any help is greatly appreciated.
    Thanks
     
    author
    Posts: 11962
    5
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Apparently your code is not setting the SOAP-Action header. You can do it with

    [ March 10, 2004: Message edited by: Lasse Koskela ]
     
    Ranch Hand
    Posts: 5093
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Originally posted by Balaji Loganathan:
    Read the documentation on using the pretty-tiny tool WSDL2Java


    How to get WSDL2Java to work though... Whenever I try I get an error


    C:\work\Java\SOAP\zip>java -cp %AXISCP% org.apache.axis.wsdl.WSDL2Java ZipServic
    e.wsdl
    Exception in thread "main" java.lang.NoClassDefFoundError: javax.wsdl.Definition
    at org.apache.axis.wsdl.toJava.JavaGeneratorFactory.class$(JavaGeneratorFactory.java:163)
    at org.apache.axis.wsdl.toJava.JavaGeneratorFactory.addDefinitionGenerators(JavaGeneratorFactory.java:163)
    at org.apache.axis.wsdl.toJava.JavaGeneratorFactory.addGenerators JavaGeneratorFactory.java:133)
    at org.apache.axis.wsdl.toJava.JavaGeneratorFactory.<init> JavaGeneratorFactory.java:120)
    at org.apache.axis.wsdl.toJava.Emitter.<init>(Emitter.java:120)
    at org.apache.axis.wsdl.WSDL2Java.createParser(WSDL2Java.java:172)
    at org.apache.axis.wsdl.gen.WSDL2.<init>(WSDL2.java:113)
    at org.apache.axis.wsdl.WSDL2Java.<init>(WSDL2Java.java:161)
    at org.apache.axis.wsdl.WSDL2Java.main(WSDL2Java.java:289)


    AXISCP is


    AXISCP=c:\tools\axis-1_1\lib\axis.jar;c:\tools\axis-1_1\lib\commons-discovery.jar;c:\tools\axis-1_1\lib\commons-logging.jar;c:\tools\axis-1_1\lib\log4j-1.2.8.jar;c:\tools\axis-1_1\lib\jaxrpc.jar;c:\tools\axis-1_1\lib\saaj.jar


    added some linebreaks to keep it readable
    other than that the classpath is empty so no conflicting libraries.
    Using J2SDK 1.4.2-b28 (I know Axis has trouble with 1.4 JDKs, but I suppose there must be a workaround?)
     
    Lasse Koskela
    author
    Posts: 11962
    5
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    You need the wsdl4j.jar in your classpath as well (if I remember correctly, that's where the javax.wsdl package is defined).
     
    Jeroen Wenting
    Ranch Hand
    Posts: 5093
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    cheers. Sometimes you just don't see your own mistakes however long you stare at them
     
    Ajay Chawla
    Greenhorn
    Posts: 11
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi All,
    Thanks for all those reply's.
    But my problem still remains but now in a different form.
    I modified the code as: -
    System.setProperty("javax.xml.soap.MessageFactory","weblogic.webservice.core.soap.MessageFactoryImpl");
    System.setProperty( "javax.xml.rpc.ServiceFactory","weblogic.webservice.core.rpc.ServiceFactoryImpl");
    ServiceFactory factory = ServiceFactory.newInstance();
    String targetNamespace = "http://tempuri.org/";
    QName serviceName = new QName(targetNamespace,"JavaService1");
    QName portName = new QName(targetNamespace,"JavaService1Soap");
    QName operationName = new QName("http://schemas.xmlsoap.org/soap/http","JavaTest");
    URL wsdlLocation = new URL("http://delgtel304:7070/WebService2/JavaService1.asmx?WSDL");
    Service service = factory.createService(wsdlLocation, serviceName);
    Call call = service.createCall(portName, operationName);
    call.setProperty(javax.xml.rpc.Call.SOAPACTION_USE_PROPERTY, new Boolean(true));
    call.setProperty(javax.xml.rpc.Call.SOAPACTION_URI_PROPERTY, "MySoapAction");
    String result = (String) call.invoke(new Object[] {"BEAS"});
    System.out.println("\n");
    System.out.println("This example shows how to create a dynamic client application that invokes a non-WebLogic Web service.");
    System.out.println("The webservice used was:http://services.xmethods.net/soap/urn:xmethods-delayed-quotes.wsdl");
    System.out.println("The quote for BEAS is: ");
    System.out.println(result);

    I get this on console :-
    WARNINIG: Unable to find a javaType for the xmlType:['http://tempuri.org/']:Java
    Test. Make sure that you have registered this xml type in the type mapping
    Using SOAPElement instead
    WARNINIG: Unable to find a javaType for the xmlType:['http://tempuri.org/']:Java
    TestResponse. Make sure that you have registered this xml type in the type mappi
    ng
    Using SOAPElement instead
    Exception in thread "main" javax.xml.rpc.JAXRPCException: failed to invoke opera
    tion. Error in the soap layer (jaxm); nested exception is: Message[ failed to se
    rialize xml:weblogic.xml.schema.binding.SerializationException: mapping lookup f
    ailure. class=interface javax.xml.soap.SOAPElement class context=TypedClassConte
    xt{schemaType=['http://tempuri.org/']:JavaTest}]StackTrace[
    javax.xml.soap.SOAPException: failed to serialize xml:weblogic.xml.schema.bindi
    ng.SerializationException: mapping lookup failure. class=interface javax.xml.soa
    p.SOAPElement class context=TypedClassContext{schemaType=['http://tempuri.org/']
    :JavaTest}
    at weblogic.webservice.core.DefaultPart.toXML(DefaultPart.java:266)
    at weblogic.webservice.core.DefaultMessage.toXML(DefaultMessage.java:456
    )
    at weblogic.webservice.core.DefaultOperation.invoke(DefaultOperation.jav
    a:407)
    at weblogic.webservice.core.DefaultOperation.invoke(DefaultOperation.jav
    a:363)
    at weblogic.webservice.core.rpc.CallImpl.invoke(CallImpl.java:423)
    at weblogic.webservice.core.rpc.CallImpl.invoke(CallImpl.java:292)
    at TestClient2.main(TestClient2.java:35)
    Caused by: weblogic.xml.schema.binding.SerializationException: mapping lookup fa
    ilure. class=interface javax.xml.soap.SOAPElement class context=TypedClassContex
    t{schemaType=['http://tempuri.org/']:JavaTest}
    at weblogic.xml.schema.binding.RuntimeUtils.lookup_serializer(RuntimeUti
    ls.java:144)
    at weblogic.xml.schema.binding.RuntimeUtils.invoke_serializer(RuntimeUti
    ls.java:180)
    at weblogic.xml.schema.binding.RuntimeUtils.invoke_serializer(RuntimeUti
    ls.java:167)
    at weblogic.webservice.core.DefaultPart.toXML(DefaultPart.java:258)
    ... 6 more
    ]
    at weblogic.webservice.core.rpc.CallImpl.invoke(CallImpl.java:432)
    at weblogic.webservice.core.rpc.CallImpl.invoke(CallImpl.java:292)
    at TestClient2.main(TestClient2.java:35)
    Thanks
    Ajay
     
    Ranch Hand
    Posts: 1066
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Did anybody solve this problem?. I am getting a similar error in Weblogic 8.1, when trying to invoke a web service with JAX-RPC (dynamic wsdl method).
     
    Ranch Hand
    Posts: 46
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi,

    I am also having similar problem when trying to connect to a WS using Axis client.

    Can somebody tell me what should be the value for
    ? I tried setting it to blank and some other value but I get this error regardless. What is the significance of this property?

    Thanks
     
    You showed up just in time for the waffles! And this tiny ad:
    Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    reply
      Bookmark Topic Watch Topic
    • New Topic