------------Here is my client program-------------
package calculator2;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.net.HttpURLConnection;
import java.net.URL;
//import dk.dtu.imm.ws.soap.CallResponseMessage;
//import dk.dtu.imm.ws.soap.SoapBody;
//import dk.dtu.imm.ws.soap.SoapFault;
import dk.dtu.imm.ws.soap.SoapMessage;
public class Calculator2 {
public void echo() {
String echo;
String string = "hello service";
try {
URL endPoint = new URL
("http://localhost:8080/axis/CalcServer2.jws");
HttpURLConnection connection = (HttpURLConnection) endPoint
.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("SOAPAction", """");
connection.setRequestProperty("Content-type","text/xml");
connection.setDoOutput(true);
connection.connect();
SoapMessage message = SoapMessage.createCallResponseMessage("echo",
"input", string);
sendSoapRequest(connection, message);
SoapMessage answer = receiveSoapResponse(connection);
connection.disconnect();
echo = answer.getCallResponseMessage().getArgument("echoReturn");
}
catch(Exception me){
System.err.println("Error: " + me.getMessage());
}
}
private SoapMessage receiveSoapResponse(HttpURLConnection connection)
throws IOException {
InputStream result = (InputStream) connection.getContent(); //when i debug i get an exception here: Server returned HTTP response code: 500 for URL: http://localhost:8081/axis/CalcServer2.jws
SoapMessage answer = SoapMessage.newInstance(result);
return answer;
}
private void sendSoapRequest(HttpURLConnection connection,
SoapMessage message) throws IOException {
Writer writer = new OutputStreamWriter(connection.getOutputStream());
writer.write(message.asXML());
writer.close();
}
}
------------- end of client program -----------------
------------- Here is my servlet server -------------
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import dk.dtu.imm.ws.soap.CallResponseMessage;
import dk.dtu.imm.ws.soap.SoapMessage;
public class CalcServer2 extends HttpServlet {
private static final long serialVersionUID = 1L;
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws IOException,
ServletException {
response.setContentType("text/xml");
PrintWriter writer = response.getWriter();
InputStream stream = request.getInputStream();
SoapMessage message = SoapMessage.newInstance(stream);
System.out.println("Request: "+message.asXML());
CallResponseMessage payload = message.getCallResponseMessage();
if ("echo".equals(payload.getMessageName())) {
String input = payload.getArgument(
"input");
EchoString echo = new EchoString();
String output = echo.echo(input);
SoapMessage result = SoapMessage.createCallResponseMessage(
"echoResponse", "echoReturn", output);
writer.println(result.asXML());
}
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException {
response.setContentType("text/html");
PrintWriter writer = response.getWriter();
writer
.println("
Use the post method to access the Web service.
");
}
}
class EchoString {
public String echo(String input) {
return input;
}
}
--------------------- end of servlet server------------
i use a TCPMonitor to watch the messages and i get
this failures:
------the message from client to server:---------
POST /axis/CalcServer2.jws HTTP/1.1
SOAPAction: ""
Content-type: text/xml
User-Agent: Java/1.5.0_08
Host: 127.0.0.1:8080
Accept: text/html, image/gif, image/jpeg, *; q=.2,
*/*; q=.2
Connection: keep-alive
Content-Length: 188
<?xml version="1.0" encoding="UTF-8"?
>
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"&
gt;
hello
service
<
;/soap:Envelope>
------------------ end message -------------------
----------message from server to client:----------
HTTP/1.1 500 Internal Server Error
Server: Apache-Coyote/1.1
Set-Cookie:
JSESSIONID=91487CF4D9785E87BD26D1CAB26150BB; Path=/axis
Content-Type: text/xml;charset=utf-8
Transfer-Encoding: chunked
Date: Fri, 22 Sep 2006 21:50:33 GMT
Connection: close
1f9
<?xml version="1.0" encoding="UTF-8"?
>
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope
/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-
instance">
&
lt;faultcode
xmlns:ns1="http://xml.apache.org/axis/">ns1:Client&l
t;/faultcode>
No such
operation 'echo'
s2:hostname
xmlns:ns2="http://xml.apache.org/axis/">ibm
hostname>
oapenv:Body>
0
its says :
No such
operation 'echo'
How to deal with this problem?
The server is running on tomcat/axis