By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,610 Members | 2,155 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,610 IT Pros & Developers. It's quick & easy.

MSXML2.ServerXMLHTTP to HttpWebRequest: Error 500

P: n/a
Hi,

Is it possible to force HttpWebRequest to do exactly (not approximately) the same as MSXML2.ServerXMLHTTP does?

More details. I port JScript to JScript.NET

I have a server (ASP invoking binary code; code not accessible).
I send XML requests to it.
If my request is accepted, ServerXMLHTTP returns XML with accept details.
If my request is rejected, ServerXMLHTTP returns XML with reject details.
ServerXMLHTTP always returns XML.

For accepted requests, HttpWebRequest returns the same as ServerXMLHTTP.
But for rejected requests, HttpWebRequest fails with (500) Internal Server Error.

My JScript:
function GetResponse(xmltext) {
var xmlhttp, res;
xmlhttp = new ActiveXObject("MSXML2.ServerXMLHTTP");
xmlhttp.open( "POST", MyUrl, false );
xmlhttp.setRequestHeader( "Content-Type", "text/xml" );
xmlhttp.send( xmltext );
res = xmlhttp.responseText;
xmlhttp = null;
return res;
}

My JScript.NET:
static public function GetResponse(xmltext:String):String {
var req:HttpWebRequest;
var rsp:HttpWebResponse;
var wr:StreamWriter;
var rd:StreamReader;
var res:String;
req=HttpWebRequest(WebRequest.Create(MyUrl));
req.Method='POST';
req.ContentType='text/xml';
wr=new StreamWriter(req.GetRequestStream());
try { wr.Write(xmltext); } finally { wr.Close(); }
rsp = HttpWebResponse(req.GetResponse()); // Possible Exception 500 here !!
rd=new StreamReader(rsp.GetResponseStream());
res=rd.ReadToEnd();
rd.Close();
return res;
}
I played also with Credentials, ContentLength and StreamWriter Encoding, without success.

Thank you,
Mahris
Nov 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hold on, if the request is rejected - what do you want to happen?

It doesn't sound unreasonable to have code to handle errors that may be
coming back from the server.

"Maris Janis Vasilevskis" <ma****@myself.com> wrote in message
news:eD****************@TK2MSFTNGP10.phx.gbl...
Hi,

Is it possible to force HttpWebRequest to do exactly (not approximately)
the same as MSXML2.ServerXMLHTTP does?

More details. I port JScript to JScript.NET

I have a server (ASP invoking binary code; code not accessible).
I send XML requests to it.
If my request is accepted, ServerXMLHTTP returns XML with accept details.
If my request is rejected, ServerXMLHTTP returns XML with reject details.
ServerXMLHTTP always returns XML.

For accepted requests, HttpWebRequest returns the same as ServerXMLHTTP.
But for rejected requests, HttpWebRequest fails with (500) Internal Server
Error.

My JScript:
function GetResponse(xmltext) {
var xmlhttp, res;
xmlhttp = new ActiveXObject("MSXML2.ServerXMLHTTP");
xmlhttp.open( "POST", MyUrl, false );
xmlhttp.setRequestHeader( "Content-Type", "text/xml" );
xmlhttp.send( xmltext );
res = xmlhttp.responseText;
xmlhttp = null;
return res;
}

My JScript.NET:
static public function GetResponse(xmltext:String):String {
var req:HttpWebRequest;
var rsp:HttpWebResponse;
var wr:StreamWriter;
var rd:StreamReader;
var res:String;
req=HttpWebRequest(WebRequest.Create(MyUrl));
req.Method='POST';
req.ContentType='text/xml';
wr=new StreamWriter(req.GetRequestStream());
try { wr.Write(xmltext); } finally { wr.Close(); }
rsp = HttpWebResponse(req.GetResponse()); // Possible Exception 500 here
!!
rd=new StreamReader(rsp.GetResponseStream());
res=rd.ReadToEnd();
rd.Close();
return res;
}
I played also with Credentials, ContentLength and StreamWriter Encoding,
without success.

Thank you,
Mahris

Nov 19 '05 #2

P: n/a
Thank you, Marina.
However, I cannot hold on, I need to analyze the reject message.

But I found the reason.
In the server trace I see that 500 is generated for both, ServerXMLHTTP and HttpWebRequest,
together with a good XML.
Simply, ServerXMLHTTP returns the result but HttpWebRequest throws error.

So, my current solution:
static public function GetResponse(xmltext:String):String {
var req:HttpWebRequest;
var rsp:HttpWebResponse;
var wr:StreamWriter;
var rd:StreamReader;
var res:String;
req=HttpWebRequest(WebRequest.Create(cst.SoapURL)) ;
req.Method='POST';
req.ContentType='text/xml';
wr=new StreamWriter(req.GetRequestStream());
try { wr.Write(xmltext); } finally { wr.Close(); }
try {
rsp = HttpWebResponse(req.GetResponse());
}
catch(e:System.Net.WebException) {
if(e.Status==System.Net.WebExceptionStatus.Protoco lError) {
rsp = HttpWebResponse(e.Response);
}
else throw e;
}
rd=new StreamReader(rsp.GetResponseStream());
res=rd.ReadToEnd();
rd.Close();
return res;
}

Mahris

Marina wrote:
Hold on, if the request is rejected - what do you want to happen?

It doesn't sound unreasonable to have code to handle errors that may be
coming back from the server.

"Maris Janis Vasilevskis" <ma****@myself.com> wrote in message
news:eD****************@TK2MSFTNGP10.phx.gbl...
Hi,

Is it possible to force HttpWebRequest to do exactly (not approximately)
the same as MSXML2.ServerXMLHTTP does?

More details. I port JScript to JScript.NET

I have a server (ASP invoking binary code; code not accessible).
I send XML requests to it.
If my request is accepted, ServerXMLHTTP returns XML with accept details.
If my request is rejected, ServerXMLHTTP returns XML with reject details.
ServerXMLHTTP always returns XML.

For accepted requests, HttpWebRequest returns the same as ServerXMLHTTP.
But for rejected requests, HttpWebRequest fails with (500) Internal Server
Error.

Nov 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.