T
team_l33t
Hi, i have a java file(i found it on the net) which accesses a .NET
webservice but when i execute the class file error code 500 is being
returned.
The java file is as under (it access a web service named Service1.asmx)
import java.util.Vector;
import java.net.*;
import java.io.*;
public class Test{
public byte[] marshall() {
StringBuffer payload = new StringBuffer ("<?xml version=\'1.0\'
encoding=\'UTF-8\'?>");
payload.append("<soap:Envelope xmlns:xsi=
\"http://www.w3.org/2001/XMLSchema-instance\"
xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"
xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">");
payload.append("<soap:Body>");
payload.append("<HelloWorld
xmlns=\"http://tempuri.org/WSGraduation1/Service1/\" />");
payload.append("</soap:Body>");
payload.append("</soap:Envelope>\r\n");
return payload.toString().getBytes();
}
public void post(){
try{
byte[] request = marshall();
URL endpoint = new URL("http://localhost/WSGraduation1/Service1.asmx");
URLConnection con = endpoint.openConnection ();
con.setDoInput (true);
con.setDoOutput (true);
con.setUseCaches (false);
con.setAllowUserInteraction(false);
con.setRequestProperty ("Content-Length", Integer.toString
(request.length));
con.setRequestProperty ("Content-Type", "text/xml");
con.setRequestProperty
("SOAPAction","\"http://tempuri.org/SOAP/HelloWorld\"");
OutputStream out = con.getOutputStream ();
out.write (request);
out.flush ();
out.close();
InputStream in = con.getInputStream();
int i= -1;
while((i = in.read()) > -1){
System.out.print((char)i);
}
}
catch(MalformedURLException e1){
System.out.println(e1.getMessage());
}
catch(IOException e2){
System.out.println(e2.getMessage());
System.out.println(e2);
}
}
public static void main(String[] args){
Test sc = new Test();
sc.marshall();
sc.post();
}
}
webservice but when i execute the class file error code 500 is being
returned.
The java file is as under (it access a web service named Service1.asmx)
import java.util.Vector;
import java.net.*;
import java.io.*;
public class Test{
public byte[] marshall() {
StringBuffer payload = new StringBuffer ("<?xml version=\'1.0\'
encoding=\'UTF-8\'?>");
payload.append("<soap:Envelope xmlns:xsi=
\"http://www.w3.org/2001/XMLSchema-instance\"
xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"
xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">");
payload.append("<soap:Body>");
payload.append("<HelloWorld
xmlns=\"http://tempuri.org/WSGraduation1/Service1/\" />");
payload.append("</soap:Body>");
payload.append("</soap:Envelope>\r\n");
return payload.toString().getBytes();
}
public void post(){
try{
byte[] request = marshall();
URL endpoint = new URL("http://localhost/WSGraduation1/Service1.asmx");
URLConnection con = endpoint.openConnection ();
con.setDoInput (true);
con.setDoOutput (true);
con.setUseCaches (false);
con.setAllowUserInteraction(false);
con.setRequestProperty ("Content-Length", Integer.toString
(request.length));
con.setRequestProperty ("Content-Type", "text/xml");
con.setRequestProperty
("SOAPAction","\"http://tempuri.org/SOAP/HelloWorld\"");
OutputStream out = con.getOutputStream ();
out.write (request);
out.flush ();
out.close();
InputStream in = con.getInputStream();
int i= -1;
while((i = in.read()) > -1){
System.out.print((char)i);
}
}
catch(MalformedURLException e1){
System.out.println(e1.getMessage());
}
catch(IOException e2){
System.out.println(e2.getMessage());
System.out.println(e2);
}
}
public static void main(String[] args){
Test sc = new Test();
sc.marshall();
sc.post();
}
}