How to make a Java Soap Call...

Posted on 2009-04-20
Last Modified: 2013-11-18
I have been given instructions to create a soap request with the following information.  I obviuosly have no idea what I'm doing, can someone help me here....  I have attached code which is a "start" but not quite there.  And I have no idea what uri to use??

(SOAP 1.1)
-------------- START --------------------------
POST /htm2pdf.asmx HTTP/1.1
Content-Type: text/xml; charset=utf-8
Content-Length: [length]
SOAPAction: ""

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="" xmlns:xsd="" xmlns:soap="">
    <Htm2PdfDoc xmlns="">
------------------ END ---------------------

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


	String url = "";

	String uri = "????";   // WHAT DO I PUT HERE??

	String methodName = "Htm2PdfDoc";

	String uniqueKey = "12345";		

	String htmlText = "<html><body><h1>Hello World!</h1></body></html>";


	Call call = new Call();




	Vector params = new Vector();

	params.addElement(new Parameter("html", String.class, htmlText, null));

	params.addElement(new Parameter("key", String.class, uniqueKey, null));


	URL service = new URL(url);

	Response translation = call.invoke(service, "");

	Parameter result = null;

	if (translation.generatedFault()) {

		Fault fault = translation.getFault();

		System.err.println("Generated fault: " + fault);

	} else {

		result = translation.getReturnValue();




Open in new window

Question by:burtonrhodes
    LVL 92

    Expert Comment

    think the uri should be the name of the service you are calling


    Expert Comment

    Yes, it should be the name of the service, something like :


    Open in new window

    LVL 3

    Author Comment

    Yes... that is the question isn't it :)  I have no idea what "the name of the service is".  Is this something that I will have to find out from the service developer?  For some reason they didn't tell me in the documentation.  Do I really need to input the uri??  Is it required?

    Their test code is not in java but written this way (but I see no uri code here)....

    Dim objHtm2Pdf As New htm2pdf.htm2pdf
    Dim pdfBytes As Byte() = objHtm2Pdf.Htm2PdfDoc("<p>Some HTML</p>", "<your unique key here >")

    Dim objFileStream As System.IO.FileStream
    objFileStream = New System.IO.FileStream("c:\aDocument.pdf", System.IO.FileMode.Create)
    objFileStream.Write(pdfBytes, 0, pdfBytes.Length)

    Expert Comment

    At is the service description, I think the service name is htm2pdf. Try htm2pdf or as URI.
    LVL 3

    Author Comment

    I think you may be right with   I'll do some testing a bit later today and let you know.
    LVL 23

    Expert Comment

    First of let me know what framework are u using? you may have to use something like axis and then need to make a direct call similar to the one I have answered here

    Please not you must and should set the SOAPAction header in the http header for proper invocation of your service.
    LVL 23

    Accepted Solution

    ok here is a working axis direct client , try it with some valid key
    package com;
    import javax.xml.namespace.QName;
    import javax.xml.rpc.ParameterMode;
    import org.apache.axis.client.Call;
    import org.apache.axis.client.Service;
    import org.apache.axis.encoding.XMLType;
    public class DirectClient {
    	public static void main(String[] args) throws Exception {
            String url = "";
            String uri = "";   // WHAT DO I PUT HERE??
            String methodName = "Htm2PdfDoc";
            String uniqueKey = "12345";             
            String htmlText = "<html><body><h1>Hello World!</h1></body></html>";
            try {
                String endpoint =  url;
                Service  service = new Service();
                Call call= (Call) service.createCall();
                //call.setProperty( Call.SOAPACTION_USE_PROPERTY, new Boolean( true ) );
               // call.setProperty( Call.SOAPACTION_URI_PROPERTY, "http://www.webserviceX.NET/GetQuote");
                call.setProperty(Call.SOAPACTION_USE_PROPERTY, new Boolean(true));
                call.setProperty(Call.SOAPACTION_URI_PROPERTY, uri );
                QName html = new QName("","html");
                QName key = new QName("","key");
                call.addParameter(html,XMLType.XSD_STRING, ParameterMode.IN);
                call.addParameter(key,XMLType.XSD_STRING, ParameterMode.IN);
                call.setTargetEndpointAddress( new );
                call.setOperationName(new QName("", methodName) );
    //            System.out.println(call.);
                Object obj = call.invoke( new Object[] { htmlText , uniqueKey} );
               // Exception e = (Exception) obj;
                System.out.println("RESULT:" + obj + "'");
              //  e.printStackTrace();
         } catch (Exception e) {

    Open in new window

    LVL 3

    Author Closing Comment

    Holy crap.  That was the best answer I've ever recieved on Experts-exchange.  Works like charm.  a+++

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Training Course: Java/J2EE and SOA

    This course will cover both core and advanced Java concepts like Database connectivity, Threads, Exception Handling, Collections, JSP, Servlets, XMLHandling, and more. You'll also learn various Java frameworks like Hibernate and Spring.

    Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
    Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now