http Request

I

Iain Adams

Hello, this is a sample app but it doesnt seem to work. I am trying to
get my head round this.

I have a html doc that goes:

POST /webservices/Service1.asmx/HelloWorld HTTP/1.1
Host: 192.168.1.153
Content-Type: application/x-www-form-urlencoded
Content-Lengt: 3495

this is a http request for the webservice HelloWorld. I know the
webservice works but how do i actually get the response. I hope this
makes sense. When I load this into my browser it just shows the request
in text. do i need to add some html tags or something. Any help would
be wonderful
 
I

Iain Adams

okay i have worked out that i need to open a socket and send the
request that way. I think it is all becoming clearer.
 
M

Marcin Hoppe

Iain said:
okay i have worked out that i need to open a socket and send the
request that way. I think it is all becoming clearer.

Why don't you try to generate a stub for your Web services with Visual
Studio or WSDL.exe tool that comes with .NET Framework SDK?

If you want to handcraft your Web service client, derive from a
SoapHttpClientProtocol base class and implement your Web services calls
by means of this class. It will be still a lot easier than sending SOAP
messages via HTTP.

In .NET there is a simpler way to handle HTTP than operating on raw
sockets. Please read about WebRequest, HttpWebRequest and
HttpWebResponse classes.

These classes make life a little bit easier, but if you wan't to invoke
Web services this way, prepare for a tough challenge of actually
constructing and parsing SOAP messages yourself.

Best regards!
Marcin
 
M

Morten Wennevik

Hi Iain,

Provided the web service supports httpget/post you can simply do

HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create("http://<host>/webservices/Service1.asmx/HelloWorld");
using (HttpWebResponse resp = (HttpWebResponse)req.GetResponse())
{
using (StreamReader sr = new StreamReader(resp.GetResponseStream()))
{
string returndata = sr.ReadToEnd();
}
}
 
M

Morten Wennevik

Btw, a quick check to see if this works is to load the uri in a browser, you would then see the returnstring in the browser as well. Note though that the return stream may be in xml format.
 
I

Iain Adams

Thanks, I will check them out right away.

O and the browser does return the string in xml but is actually quite
helpful.

Thanks again
 

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

Top