VB-Script in C#

M

mancha28

Hi,

I would write the following code in C#.

set objHTTP = CreateObject("Msxml2.XMLHTTP")
objHTTP.open "POST", "http://url.com", False
objHTTP.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
objHTTP.setRequestHeader "SOAPAction", "urn:blabla#ListOfTitles"

objHTTP.send fullString

strReturn = objHTTP.responseText

Can anybody help me, please?
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi ,

You can do it, but it's not the best option, the framework provides classes
to make a http request and get the response.

Take a look at WebRequest class.


cheers,
 
M

mancha28

Now, I have implemented this code in C#. It works without exceptions
but the response is empty. Is this an error of the web service?
When I execute the above code then the result isn't empty. I get a list
of titles back.

Another question: How can I implement the object ASync in
HttpWebRequest class? This is a parameter of XMLHTTP.open.

My code in C#:

HttpWebRequest requ =
(HttpWebRequest)HttpWebRequest.Create("http://url.com");
requ.Method = "POST";

requ.ContentType = "text/xml; charset=utf-8";
requ.Headers.Add("SOAPAction", "urn:blabla#ListOfTitles");

requ.ContentLength = fullstr.Length;
StreamWriter sw = new StreamWriter(requ.GetRequestStream());

sw.Write(fullstr);
sw.Close();

HttpWebResponse resp = (HttpWebResponse) requ.GetResponse();
StreamReader myStreamReader = new
StreamReader(resp.GetResponseStream());

myStreamReader.ReadToEnd();
myStreamReader.Close();
resp.Close();
 
M

mancha28

I have found the error and the call to the web servie works fine.
Instead of 'myStreamReader.ReadLine()' I had written
'myStreamReader.ReadToEnd()'. The response of web service is the right
result.
 

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