Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Services > Calling an HTTP server

Reply
Thread Tools

Calling an HTTP server

 
 
Amir
Guest
Posts: n/a
 
      03-12-2007
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();

}
}


 
Reply With Quote
 
 
 
 
Andrew Brook
Guest
Posts: n/a
 
      03-12-2007
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" <> wrote in message
news:3592E05C-4530-41B8-B96C-...
> 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();
>
> }
> }
>
>



 
Reply With Quote
 
 
 
 
Amir
Guest
Posts: n/a
 
      03-12-2007
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" wrote:

> 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" <> wrote in message
> news:3592E05C-4530-41B8-B96C-...
> > 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();
> >
> > }
> > }
> >
> >

>
>
>

 
Reply With Quote
 
Andrew Brook
Guest
Posts: n/a
 
      03-12-2007
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" <> wrote in message
news:A5A736A0-9061-40C3-80F7-...
> 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" wrote:
>
>> 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" <> wrote in message
>> news:3592E05C-4530-41B8-B96C-...
>> > 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();
>> >
>> > }
>> > }
>> >
>> >

>>
>>
>>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
HTTP SOAP/HTTP GET/HTTP POST milan_9211 Software 0 01-10-2011 02:10 PM
The Web server reported the following error when attempting to create or open the Web project located at the following URL: 'http://localhost/822319ev1'. 'HTTP/1.1 500 Internal Server Error'. chanmm ASP .Net 2 09-07-2010 07:37 AM
multitask http server (single-process multi-connection HTTP server) lkcl Python 6 07-15-2010 10:39 PM
Can I change the response URL to http://server/page.XLS instead of http://server/page.ASPX ? guillermojco@gmail.com ASP .Net 3 04-26-2007 04:49 AM
Server Side button calling page_load before calling it's own click event. Ryan Ternier ASP .Net 4 07-29-2004 01:06 PM



Advertisments