Calling an HTTP server

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();

}
}
 
A

Andrew Brook

Hiya,

I haven't had to look at accessing a Java web service before, but in the
majority of cases you'd think it should be the same as accessing any other
web service ;)

try searching for examples including "SoapHttpClientProtocol". You should be
able to create a class that inherits from that one, hopefully that should
wrap up any of the SOAP messages you need to send.

Andrew
 
A

Amir

Hi Andrew

Thanks for the post.

The HTTP server code is not exposed as a web service. The Java guys are
using the code below to send it a SOAP message. The HTTP server code
processes the SOAP message's payload, takes appropriate action and the
returns a result (in SOAP format).

There is no WSDL etc: I need to work at a lower level which is why I was
looking at the HttpWebRequest class example.

I hope that helps!?!!

Andrew Brook said:
Hiya,

I haven't had to look at accessing a Java web service before, but in the
majority of cases you'd think it should be the same as accessing any other
web service ;)

try searching for examples including "SoapHttpClientProtocol". You should be
able to create a class that inherits from that one, hopefully that should
wrap up any of the SOAP messages you need to send.

Andrew

Amir said:
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();

}
}
 
A

Andrew Brook

Hiya,

So i take it your current code looks something like the following (if you
coded in VB that is) ?

Dim webrReq As HttpWebRequest =
CType(WebRequest.Create("http://www.blahblah.com/"), HttpWebRequest)

Dim strmReq As System.IO.Stream = webrReq .GetRequestStream()

'write some file data to the stream

Dim webresp As HttpWebResponse = myReq.GetResponse()


Andrew

Amir said:
Hi Andrew

Thanks for the post.

The HTTP server code is not exposed as a web service. The Java guys are
using the code below to send it a SOAP message. The HTTP server code
processes the SOAP message's payload, takes appropriate action and the
returns a result (in SOAP format).

There is no WSDL etc: I need to work at a lower level which is why I was
looking at the HttpWebRequest class example.

I hope that helps!?!!

Andrew Brook said:
Hiya,

I haven't had to look at accessing a Java web service before, but in the
majority of cases you'd think it should be the same as accessing any
other
web service ;)

try searching for examples including "SoapHttpClientProtocol". You should
be
able to create a class that inherits from that one, hopefully that should
wrap up any of the SOAP messages you need to send.

Andrew

Amir said:
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();

}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top