A
Amir
Hi
I am trying to replicate a price of Java code in .NET (the Java code is at
the end of this post).
Basically, I need to send a SOAP message to an HTTP server program (that
happens to be written in Java). I have been Googling for the past 4-5 hours
and found 3-4 samples but non of them seem to work. My latest error is
The remote server returned an error: (405) Method Not Allowed
My .NET code is using the HttpWebRequest, which is very poorly documented by
Microsoft.
Does anyone have sample code for what I am trying to do?
Thanks in advance
------------------------
Here is the Java code (that works)
import java.io.*;
import java.net.URL;
import java.net.URLConnection;
/**
* @version $Revision: 426415 $
*/
public class HttpClient {
public static void main(String[] args) throws Exception {
URLConnection connection = new URL(args[0]).openConnection();
connection.setDoOutput(true);
OutputStream os = connection.getOutputStream();
// Post the request file.
FileInputStream fis = new FileInputStream(args[1]);
//Buffer
byte[] buf = new byte[256];
for (int c = fis.read(buf); c != -1; c = fis.read(buf)) {
os.write(buf,0,c);
}
os.close();
fis.close();
// Read the response.
BufferedReader in = new BufferedReader(new
InputStreamReader(connection.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null) {
System.out.println(inputLine);
}
in.close();
}
}
I am trying to replicate a price of Java code in .NET (the Java code is at
the end of this post).
Basically, I need to send a SOAP message to an HTTP server program (that
happens to be written in Java). I have been Googling for the past 4-5 hours
and found 3-4 samples but non of them seem to work. My latest error is
The remote server returned an error: (405) Method Not Allowed
My .NET code is using the HttpWebRequest, which is very poorly documented by
Microsoft.
Does anyone have sample code for what I am trying to do?
Thanks in advance
------------------------
Here is the Java code (that works)
import java.io.*;
import java.net.URL;
import java.net.URLConnection;
/**
* @version $Revision: 426415 $
*/
public class HttpClient {
public static void main(String[] args) throws Exception {
URLConnection connection = new URL(args[0]).openConnection();
connection.setDoOutput(true);
OutputStream os = connection.getOutputStream();
// Post the request file.
FileInputStream fis = new FileInputStream(args[1]);
//Buffer
byte[] buf = new byte[256];
for (int c = fis.read(buf); c != -1; c = fis.read(buf)) {
os.write(buf,0,c);
}
os.close();
fis.close();
// Read the response.
BufferedReader in = new BufferedReader(new
InputStreamReader(connection.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null) {
System.out.println(inputLine);
}
in.close();
}
}