Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Services / March 2007

Tip: Looking for answers? Try searching our database.

Calling an HTTP server

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Amir - 12 Mar 2007 15:19 GMT
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 - 12 Mar 2007 16:00 GMT
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

> Hi
>
[quoted text clipped - 57 lines]
>    }
> }
Amir - 12 Mar 2007 16:09 GMT
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!?!!

> Hiya,
>
[quoted text clipped - 69 lines]
> >    }
> > }
Andrew Brook - 12 Mar 2007 16:38 GMT
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

> Hi Andrew
>
[quoted text clipped - 88 lines]
>> >    }
>> > }
Andrew Brook - 12 Mar 2007 16:53 GMT
just worth mentioning my code snippet had bugs in it (variable names not
quite matching...)

Andrew

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 = strmReq.GetResponse()

> Hiya,
>
[quoted text clipped - 105 lines]
>>> >    }
>>> > }
Amir - 12 Mar 2007 17:32 GMT
Hi

My code is very similar to the following sample code:

http://www.thescripts.com/forum/thread427794.html

Amir

> just worth mentioning my code snippet had bugs in it (variable names not
> quite matching...)
[quoted text clipped - 119 lines]
> >>> >    }
> >>> > }

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.