|
Hi there,
I've been having a problem for days regarding the following bit of code. Basically, I have a web service which looks like this...
<br />
[WebMethod]<br />
public DataSet TestMethod1(string input)<br />
{<br />
DataSet ds;<br />
ds = new DataSet();<br />
ds.Tables.Add("HIHI");<br />
return ds; <br />
}<br />
...and some code that calls it which looks like this
<br />
HttpWebRequest httpRequest;<br />
HttpWebResponse httpResponse;<br />
byte[] inputs=null;<br />
UTF8Encoding encoding = new UTF8Encoding();; <br />
for(int i=0;i<3;i++)<br />
{ <br />
httpRequest = (HttpWebRequest)HttpWebRequest.Create("http://localhost/StaticSer/Service1.asmx/TestMethod1");<br />
httpRequest.Method = "POST";<br />
httpRequest.Credentials = new NetworkCredential("", "", "");<br />
httpRequest.KeepAlive = true;<br />
httpRequest.AllowWriteStreamBuffering = true;<br />
httpRequest.AllowAutoRedirect = true;<br />
httpRequest.ContentType = "application/x-www-form-urlencoded";<br />
<br />
if(i==0)<br />
inputs = encoding.GetBytes(@"INPUT=someInput_1");<br />
<br />
if(i==1)<br />
inputs = encoding.GetBytes(@"INPUT=someInput_2");<br />
<br />
if(i==2)<br />
inputs = encoding.GetBytes(@"INPUT=someInput_3");<br />
<br />
httpRequest.ContentLength = inputs.Length;<br />
httpRequest.GetRequestStream().Write(inputs, 0, inputs.Length);<br />
httpResponse = (HttpWebResponse)httpRequest.GetResponse();<br />
<br />
httpResponse.Close();<br />
httpRequest=null;<br />
httpResponse = null; <br />
}<br />
The problem is that it runs perfectly fine the first time in the loop, but times out on httpRequest.GetRequestStream().Write(inputs, 0, inputs.Length); thereafter.
I am using vs2003 at the moment, and the strange thing is that the code above seem to work perfectly fine in vs2005.
Another thing I've discovered is that the above code works if the web service takes no inputs, e.g.
public DataSet TestMethod1() and
....<br />
inputs = encoding.GetBytes("");<br />
....
I'm guessing it might have something to do with httpRequest not releasing resources after the first run, but am at a lost to know how to be sure. I'd appreciate it if someone could give me some pointers. Thanks
|
|
|
|
|
You have to close the stream from your request:
httpRequest.GetRequestStream().Close();
In fact, I would recommend the following code:
<code>
using (Stream requestStream = httpRequest.GetRequestStream())
{
requestStream.Write(inputs, 0, inputs.Length);
}</code>
-----
You seem eager to impose your preference of preventing others from imposing their preferences on others. -- Red Stateler, Master of Circular Reasoning and other fallacies
If atheism is a religion, then not collecting stamps is a hobby. -- Unknown
God is the only being who, to rule, does not need to exist. -- Charles Baudelaire
|
|
|
|
|
Hi
I have developed a Client-Server application using socket.When Client side application executes on another system an error occures(Only one usage of each socket address (protocol/network address/port) is normally permitted).But already a TcpListener application has been executed on that system .I need both application to be executed simultaneously.
How to solve this problem???Plz help me.......
Thanks
Smithakrishnan
|
|
|
|
|
Hi!
You can use both applications "on the same time and same system", but just not on the same port. You'll have to reconfigure the port for one of the applications, no way around it!
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
Hi,
I have a problem that connects to my database (on the same machine) using the usual c#/vs connectionString. When I publish it, that string is still the same (i.e. the name of the machine doesn't change). Yea, I think I've hardcoded the connectionString. But how can I softcode it using VS? How can I make it so that the connectionString takes the name of the current machine it is residing on or better, the application would prompt for where the database is.
Any help is appreciated? Or even just point me to articles.
Thanks.
|
|
|
|
|
Just use the app.config - file to set up your connection-strings.
It's easy to administrate and flexible (all you will need is a text-editor).
If this is not what you want, use a static connection string and use
string.replace
to replace your computer name with the one you get from System.Net.Dns.GetHostName()
(I don't recommend this - normaly another DB will require another login etc.)
|
|
|
|
|
Theres a ConnectionStringBuilder class in the framework somewhere that acts like a dictionary. Then you can add the machine name on at runtime.
|
|
|
|
|
Specify localhost as the server?
I use custom configuration files; if the program can't find the file it pops up a dialog to get the names of the server and database from the user then stores that information in the configuration file.
|
|
|
|
|
Hi All,
I am using Dundas for creating Chart. i am facing one problem. i have created one bar chart with one series. Now some bars are coming with one color.Now what i want is to set the color dynamically of all datapoints with different color.How will i achieve it when i have only one series. Can anybody tell me how can i set the different color for all the datapoints in single series.
Thanks in Advance
Avesh
|
|
|
|
|
You should really ask this on the dundas support forums. Application/vendor specific problems are normally best dealt with by the relevant team.
|
|
|
|
|
hi
my aim is to store(transfer) the data from sql server 2005 database into excel file if any one is having any idea abt this then plz do let me know ...
regards
sindhu tiwari
ek jahaan mukkamal nahi hai zindagi ....jahan aur bhi hai is jahaan se aagey
|
|
|
|
|
You can use either Excel object model or Ole DB driver for excel to write to an excel file
|
|
|
|
|
This question has been asked hundreds of times, try searching Google[^], articles, or the forums.
I'm going to become rich when I create a device that allows me to punch people in the face over the internet.
"If an Indian asked a programming question in the forest, would it still be urgent?" - John Simmons / outlaw programmer
|
|
|
|
|
How can i change the system date style formate through code.
I have a project when it starts it compare the current date withe the condition date is the date formate is wrong it give error plz help me out.
|
|
|
|
|
|
Thanks for providing such a good link.
But my problem is not getting system data formate.
Because in Microsoft.Win32 Api there is method
GetSystemDateFormate
but there is not Setting the System Date formate
Can you help me out form this problem.
|
|
|
|
|
You shouldn't change the system's format!
Instead:
1. Retrieve the current date
2. Reformat it to the format you require
3. Compare
If you use the DateTime.Parse() method you shouldn't even need to do this as it will handle all date and date/time formats for you.
|
|
|
|
|
You asked the same question yesterday and were informed that this was not a good idea back then. Why do you think you'll get a different answer today?
The simple answer is that your application should not change the behaviour of the system to suit itself - this is a bad thing to do because you are upsetting the customer experience of the system. Instead, you need to bite the bullet and actually do some work yourself - if your code requires a particular date format, use the DateTime class to manage this in your code. This is the responsible, professional thing to do and you could have achieved this in the time you've spent faffing about trying to get people to tell you how to upset your users.
|
|
|
|
|
How to remove the databinding of the textbox control at runtime?
Jo
|
|
|
|
|
textBox1.DataBindings.RemoveAt (0);
123
|
|
|
|
|
but, it is not working.......
Jo
|
|
|
|
|
For my game I created a class called "Integer" to use with by ComboBox. For somereason the ComboBox says "TANK.Integer".
<br />
class Integer<br />
{<br />
public int value;<br />
<br />
public Integer(int value)<br />
{<br />
this.value = value;<br />
}<br />
<br />
public int Value<br />
{<br />
get<br />
{<br />
return this.value;<br />
}<br />
}<br />
<br />
new public string ToString()<br />
{<br />
return this.value.ToString();<br />
}<br />
}<br />
In the constructor that is used in Application.run I call:
<br />
MessageBox.Show(Game.grid_height_configurations[0].ToString()); <- An array of "Integers"<br />
It says "TANK.Integer" instead of calling Integer's ToString method. It's probably something small.
|
|
|
|
|
In your integer class, you should override the ToString() method:
<br />
public override string ToString()<br />
{<br />
return this.value.ToString();<br />
}<br />
|
|
|
|
|
Heh I was right it was something small. Thanks.
|
|
|
|
|
and you should not ignore (or suppress) compiler warnings either. it did tell you what was probably wrong.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|