The moose likes Web Services and the fly likes how to invoke a webservice Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "how to invoke a webservice" Watch "how to invoke a webservice" New topic

how to invoke a webservice

Ajay Chawla

Joined: Jan 14, 2004
Posts: 11
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?
Balaji Loganathan
author and deputy

Joined: Jul 13, 2001
Posts: 3150
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.

  • Spritle Software Blogs
    Ajay Chawla

    Joined: Jan 14, 2004
    Posts: 11
    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 Chawla

    Joined: Jan 14, 2004
    Posts: 11
    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");
    Vector vParam = new Vector();
    vParam.addElement(new org.apache.soap.rpc.Parameter"str",String.class,"Ajay",null));
    org.apache.soap.rpc.Response resp = call.invoke(url, "");

    org.apache.soap.Fault fault = resp.getFault();
    System.out.println("faultcode :"+fault.getFaultCode());
    System.out.println("faultString :"+fault.getFaultString());
    org.apache.soap.rpc.Parameter result = resp.getReturnValue();
    any help is greatly appreciated.
    Lasse Koskela

    Joined: Jan 23, 2002
    Posts: 11962
    Apparently your code is not setting the SOAP-Action header. You can do it with

    [ March 10, 2004: Message edited by: Lasse Koskela ]

    Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
    Jeroen Wenting
    Ranch Hand

    Joined: Oct 12, 2000
    Posts: 5093
    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
    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


    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

    Joined: Jan 23, 2002
    Posts: 11962
    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

    Joined: Oct 12, 2000
    Posts: 5093
    cheers. Sometimes you just don't see your own mistakes however long you stare at them
    Ajay Chawla

    Joined: Jan 14, 2004
    Posts: 11
    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.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("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: ");

    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
    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
    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/']
    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
    at weblogic.webservice.core.DefaultOperation.invoke(DefaultOperation.jav
    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
    at weblogic.xml.schema.binding.RuntimeUtils.lookup_serializer(RuntimeUti
    at weblogic.xml.schema.binding.RuntimeUtils.invoke_serializer(RuntimeUti
    at weblogic.xml.schema.binding.RuntimeUtils.invoke_serializer(RuntimeUti
    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)
    Vishwa Kumba
    Ranch Hand

    Joined: Aug 27, 2003
    Posts: 1064
    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).
    Niral Trivedi
    Ranch Hand

    Joined: Nov 26, 2001
    Posts: 46

    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?

    I agree. Here's the link: http://aspose.com/file-tools
    subject: how to invoke a webservice
    Similar Threads
    How is web service compostion implemented programatically?
    Webshere Integration Developer issues
    webservices swings
    How to send xml file to a different web server
    Invoking a https webservice