HttpWebRequest/Response problem - HELP

T

Taryon

Hi All!

i have an handler to save some informations on the database. works very
fine. well. i change the sql INSERT string to include a new item. Now im
getting an INTERNAL SERVER ERROR - 500. and even i change to old code i
still have the error.



This is the client code.
HttpWebRequest req1 =
(HttpWebRequest)WebRequest.Create(serverUrlTextbox.Text);
req1.Method = "PUT";
req1.AllowWriteStreamBuffering = true;
Stream reqS = req1.GetRequestStream();
StreamWriter wrtr1 = new StreamWriter(reqS);
wrtr1.WriteLine("AGENT=5555");
wrtr1.WriteLine(DateTime.Now.ToShortDateString());
wrtr1.WriteLine(DateTime.Now.ToShortTimeString());
wrtr1.WriteLine("*");

for (int i = 0; i < 3; i++)
{
wrtr1.WriteLine("information");
}
wrtr1.Close();



// Submit the request and get the response object
HttpWebResponse resp1 = (HttpWebResponse) req1.GetResponse();
// Retrieve the response stream and wrap in a StreamReader
Stream respStream1 = resp1.GetResponseStream();
StreamReader rdr1 = new StreamReader(respStream1);
// Read through the response line-by-line
string inLine1 = rdr1.ReadLine();
rdr1.Close();
}

==================================

This is the Handler code

// Read the incoming data
inLine=codes[1];
//sw.WriteLine("agente");
string sqla="INSERT INTO CHARGES(AGENT, DATAOCORRENCIA, HORAOCORRENCIA)
VALUES (";
string pvez="'";
while (inLine != null)
{
sqla+=pvez+inLine+"'";
inLine = rdr.ReadLine();
pvez=",'";
if (inLine=="*") break;
}
sqla+=")";
//sw.WriteLine(sqla);
OdbcCommand cmd1 = new OdbcCommand(sqla,conn);
cmd1.ExecuteNonQuery();
OdbcCommand cmdx = new OdbcCommand("SELECT @@IDENTITY", conn);
long nId = Convert.ToInt64(cmdx.ExecuteScalar());
inLine = rdr.ReadLine();
string sql3="";
while (inLine != null)
{
sql3="INSERT INTO ALLCUST(CHARGE, ENQUADRAMENTO) VALUES
("+nId.ToString()+",'"+inLine+"')";
OdbcCommand cm = new OdbcCommand(sql3,cnn);
cm.ExecuteNonQuery();
inLine=rdr.ReadLine();
}
wrtr.WriteLine("fim");
wrtr.Flush();

========================

I receive the error in this line of the client code.

// Submit the request and get the response object
HttpWebResponse resp1 = (HttpWebResponse) req1.GetResponse();

PS. this is the code that was working before. The change that i did was a
new line writed in the client code and a new item in the select server code.
 
T

Taryon

INTERNAL SERVER ERROR - 500
this is the error. In agreement with the docs this is because the request
was not correctly filled. Could it be because timeout?
sds

Pete Davis said:
I assume an exception is being thrown in the app. What is the exception?

Pete

--
http://www.petedavis.net
Taryon said:
Hi All!

i have an handler to save some informations on the database. works very
fine. well. i change the sql INSERT string to include a new item. Now im
getting an INTERNAL SERVER ERROR - 500. and even i change to old code i
still have the error.



This is the client code.
HttpWebRequest req1 =
(HttpWebRequest)WebRequest.Create(serverUrlTextbox.Text);
req1.Method = "PUT";
req1.AllowWriteStreamBuffering = true;
Stream reqS = req1.GetRequestStream();
StreamWriter wrtr1 = new StreamWriter(reqS);
wrtr1.WriteLine("AGENT=5555");
wrtr1.WriteLine(DateTime.Now.ToShortDateString());
wrtr1.WriteLine(DateTime.Now.ToShortTimeString());
wrtr1.WriteLine("*");

for (int i = 0; i < 3; i++)
{
wrtr1.WriteLine("information");
}
wrtr1.Close();



// Submit the request and get the response object
HttpWebResponse resp1 = (HttpWebResponse) req1.GetResponse();
// Retrieve the response stream and wrap in a StreamReader
Stream respStream1 = resp1.GetResponseStream();
StreamReader rdr1 = new StreamReader(respStream1);
// Read through the response line-by-line
string inLine1 = rdr1.ReadLine();
rdr1.Close();
}

==================================

This is the Handler code

// Read the incoming data
inLine=codes[1];
//sw.WriteLine("agente");
string sqla="INSERT INTO CHARGES(AGENT, DATAOCORRENCIA, HORAOCORRENCIA)
VALUES (";
string pvez="'";
while (inLine != null)
{
sqla+=pvez+inLine+"'";
inLine = rdr.ReadLine();
pvez=",'";
if (inLine=="*") break;
}
sqla+=")";
//sw.WriteLine(sqla);
OdbcCommand cmd1 = new OdbcCommand(sqla,conn);
cmd1.ExecuteNonQuery();
OdbcCommand cmdx = new OdbcCommand("SELECT @@IDENTITY", conn);
long nId = Convert.ToInt64(cmdx.ExecuteScalar());
inLine = rdr.ReadLine();
string sql3="";
while (inLine != null)
{
sql3="INSERT INTO ALLCUST(CHARGE, ENQUADRAMENTO) VALUES
("+nId.ToString()+",'"+inLine+"')";
OdbcCommand cm = new OdbcCommand(sql3,cnn);
cm.ExecuteNonQuery();
inLine=rdr.ReadLine();
}
wrtr.WriteLine("fim");
wrtr.Flush();

========================

I receive the error in this line of the client code.

// Submit the request and get the response object
HttpWebResponse resp1 = (HttpWebResponse) req1.GetResponse();

PS. this is the code that was working before. The change that i did was a
new line writed in the client code and a new item in the select server code.
 
J

Joerg Jooss

Taryon said:
INTERNAL SERVER ERROR - 500
this is the error. In agreement with the docs this is because the
request was not correctly filled. Could it be because timeout?

That's how the serverside reacts after the exception. What is the exception?
 
T

Taryon

I understood. but how can i know what is the exception? I can not debug the
server side (or i dont know how!).
thx for your attention!
 
J

Jon Skeet [C# MVP]

Taryon said:
I understood. but how can i know what is the exception? I can not debug the
server side (or i dont know how!).

Well what's *at* the server side? What application is it?
 
T

Taryon

This information is in my initial post. Well. a client and a server part.
BUT.
i have an client application that sends several lines to the server. these
lines is divided into 2 parts. the first one ends with a "*" and all values
is inserted into a sql server database with a odbc connection. The second
part has each line inserted into another table in the same database.
Well. i create an client app that sends 21 equal lines. all "afdasdf". I
take off the second part from the server and i got the same error. After
this, i try to send one to one the lines. Works until the 6 line. the
seventh line gives me the error.
the weird part is because the app works fine before. Ah. i got the server
app from the article:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetcomp/html/httpcomm.asp

there is a limit for sendling lines? why is working before?
sds
 
J

Jon Skeet [C# MVP]

Taryon said:
This information is in my initial post. Well. a client and a server part.

But if the server part is yours (as it looked like it was) you should
be able to debug it, if only by putting trace statements in etc to see
how far it gets.
 
T

Taryon

Well. i add the tracelistener. I already had tried the use of a streamwriter
and i got error. with tracelistener compiles ok.
BUT. Look.
if i send 6 lines to the server, the server insert the record into the
database. If i send 7 lines, i got the 500 error and the trace do not record
anything.
looks like the code is not working. The first trace is in a part of the code
that must be executed with 6 or n lines. autoflush is true. and i have no
record into the file.
thx in advance
 
J

Jon Skeet [C# MVP]

Taryon said:
Well. i add the tracelistener. I already had tried the use of a streamwriter
and i got error. with tracelistener compiles ok.
BUT. Look.
if i send 6 lines to the server, the server insert the record into the
database. If i send 7 lines, i got the 500 error and the trace do not record
anything.

In that case, your trace isn't early enough.
looks like the code is not working.

Well obviously *some* code isn't working.
The first trace is in a part of the code
that must be executed with 6 or n lines. autoflush is true. and i have no
record into the file.

Is there nothing in any other log file anywhere on the server? What
about the various event logs?
 
T

Taryon

ok. i know that "some" code is not working. im trying to say that all code
is not working. hehehe.
well the logs of the system do not show anything special about this problem.
I know that the IIS logs the visit to the sites. let me try to find this.

thx again! (sorry by the inconvenience but i need this help!)
 

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