1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| import java.net.*;
import java.io.*;
public class testSomme {
public static void main(String args[])
{
String serveur = "http://127.0.0.1:9000/testWS/NewWebService";
HttpURLConnection connection = null;
OutputStream out = null;
Writer wout = null;
String chaine = "";
InputStream in = null;
try
{
URL u = new URL(serveur);
URLConnection uc = u.openConnection();
connection = (HttpURLConnection) uc;
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setRequestMethod("POST");
out = connection.getOutputStream();
wout = new OutputStreamWriter(out);
chaine = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?> "+
"<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:q0=\"http://packageSomme/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"> "+
"<soapenv:Body>"+
"<q0:somme>"+
"<arg0>2</arg0>"+
"<arg1>3</arg1>"+
"</q0:somme>"+
"</soapenv:Body>"+
"</soapenv:Envelope>";
wout.write(chaine);
wout.flush();
wout.close();
in = connection.getInputStream();
}
catch(Exception er)
{
System.err.println("erreur grave 1 : "+er);
}
try
{
System.err.println("\r\nla chaine : \r\n"+chaine);
int c;
while ((c = in.read()) != -1) System.out.write(c);
in.close();
}
catch(Exception ee)
{
System.err.println("erreur grave 2: "+ee);
}
}
} |