Calling an HTTP server

Discussion in 'ASP .Net Web Services' started by Amir, Mar 12, 2007.

  1. Amir

    Amir Guest

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

    }
    }
     
    Amir, Mar 12, 2007
    #1
    1. Advertising

  2. Amir

    Andrew Brook Guest

    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:...
    > 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();
    >
    > }
    > }
    >
    >
     
    Andrew Brook, Mar 12, 2007
    #2
    1. Advertising

  3. Amir

    Amir Guest

    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:...
    > > 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();
    > >
    > > }
    > > }
    > >
    > >

    >
    >
    >
     
    Amir, Mar 12, 2007
    #3
  4. Amir

    Andrew Brook Guest

    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:...
    > 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:...
    >> > 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();
    >> >
    >> > }
    >> > }
    >> >
    >> >

    >>
    >>
    >>
     
    Andrew Brook, Mar 12, 2007
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ryan Ternier
    Replies:
    4
    Views:
    3,981
    Cowboy \(Gregory A. Beamer\) [MVP]
    Jul 29, 2004
  2. larkpics
    Replies:
    9
    Views:
    9,018
    Patrick.O.Ige
    Oct 22, 2005
  3. mike
    Replies:
    5
    Views:
    973
    Keith M. Corbett
    Sep 21, 2004
  4. Replies:
    3
    Views:
    802
    Guillermo
    Apr 26, 2007
  5. lkcl
    Replies:
    6
    Views:
    1,048
Loading...

Share This Page