Note that there are some explanatory texts on larger screens.

plurals
  1. POHello World in SOAP (java). How to fix it?
    primarykey
    data
    text
    <p>I'm trying to create a simple SOAP service and a SOAP client in order to run some performance tests. I'm a newbie in the usage of SOAP and I'm simply trying to adapt some code that I've found on several forums. Considering that this test will run on an embedded device I would prefer to avoid huge frameworks/libraries. I would prefer to code in java without hacking with XML.</p> <p>In the code below I'm trying to call the "sayHello" method and get the result. It's incomplete (argument is missing) but I would like to fix it in order to have a starting point for my tests.</p> <p>Can you help me to fix this example code?</p> <p>This is the code of the service class</p> <pre><code>@WebService(name = "Hello", targetNamespace = "http://localhost") public class Hello { private String message = new String("Hello, "); public void Hello() { } public String sayHello(String name) { return message + name + "."; } } </code></pre> <p>This is the code of the server class:</p> <pre><code>public class Server { protected Server() throws Exception { System.out.println("Starting Server"); Object implementor = new Hello(); String address = "http://localhost:9000/"; Endpoint.publish(address, implementor); } public static void main(String args[]) throws Exception { new Server(); System.out.println("Server ready..."); Thread.sleep(5 * 60 * 1000); System.out.println("Server exiting"); System.exit(0); } } </code></pre> <p>This is the code of a client class that is intended to send a request to the server calling the request() method:</p> <pre><code>public class Sender { . . . public void request() throws Exception { // Building the request document SOAPMessage reqMsg = MessageFactory.newInstance().createMessage(); SOAPEnvelope envelope = reqMsg.getSOAPPart().getEnvelope(); SOAPBody body = envelope.getBody(); body.addBodyElement(envelope.createName("Hello")); // Connecting and calling SOAPConnection con = SOAPConnectionFactory.newInstance() .createConnection(); SOAPMessage resMsg = con.call(reqMsg, "http://localhost:9000/"); con.close(); // Showing output System.out.println("\n\nRequest:"); reqMsg.writeTo(System.out); System.out.println("\n\nResponse:"); resMsg.writeTo(System.out); } } </code></pre> <p>The output of the client looks like:</p> <pre><code>Request: &lt;SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"&gt;&lt;SOAP-ENV:Header/&gt;&lt;SOAP-ENV:Body&gt;&lt;Hello/&gt;&lt;/SOAP-ENV:Body&gt;&lt;/SOAP-ENV:Envelope&gt; Response: &lt;?xml version="1.0" ?&gt;&lt;S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"&gt;&lt;S:Body&gt;&lt;S:Fault xmlns:ns3="http://www.w3.org/2003/05/soap-envelope"&gt;&lt;faultcode&gt;S:Client&lt;/faultcode&gt;&lt;faultstring&gt;Cannot find dispatch method for {}Hello&lt;/faultstring&gt;&lt;/S:Fault&gt;&lt;/S:Body&gt;&lt;/S:Envelope&gt; </code></pre> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload