|
I hava simple program that posts a xml file over the web to an Apache Web Service.
HttpWebRequest wr = ()WebRequest.Create(url);
wr.ContentType = "text/xml";
wr.KeepAlive = false;
wr.Timeout = 60000;
wr.Method = "POST";
Stream s = wr.RequestStream();
.....
.....
WebResponse response = wr.GetResponse();
The TCP Timeout is occuring on the wr.RequestStream() after the 5th time file sent.
Knowingly the program sends many XML files a minute. It is quite efficient producing them. However it would appear to block after the 5th one and then everything yields a TCP timeout. I increased the timeout to 1 minute on my side but yet I get the timeout within 20 seconds.
Guillermo Jimenez
|
|
|
|
|
Are you closing your connections? The number 5 seems almost programmed, like that's a connection limit. You need to make sure that you close your connections by calling Close or, better yet, use the using block statement to make sure the HttpWebResponse gets disposed (which closes the connection among other things):
using (HttpWebResponse response =
(HttpWebResponse)request.GetResponse())
{
} The using block statement compiles to a try-finally block, where it is disposed - if not null - in the finally block (so exceptions are thrown but the finally block is always executed before execution returns to the caller).
Now, if you need to allocate N number of connections like a web crawler or something, you need to control your threads. Don't just create new threads when you feel you have to. Using the ThreadPool helps in these case.
The .NET BCL also includes checks to prevent too many stops. This uses a ServicePointManager and the ServicePoint classes to limit connections. The ServicePointManager.DefaultConnectionLimit gets or sets the default number of connections. Setting that higher may help, but most servers implement their own connection limits.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Heath
You are close to becoming my personal mentor. You have answered every single one of my questions with incredible accuracy. Thanks a lot.
Back to WebResponse
I also thought that forcing the connection closed from my side was the way to go and added a finally block to set the object to null. Of course your using {} block is a much more elegant solution and I happily threw mine away to use yours. I have not tested either. I will let you know.
Look out for my next question, I'm sure you have the answer!
Guillermo
|
|
|
|
|
Setting the reference to null won't close the connection (studying the IL for the module in the assembly would help alleviate these assumptions). Even assuming it was the only reference, the GC (garbage collector) will only free the memory used by the response when the GC "feels like it" (idle time or when memory is nearly exhausted, and even then it may not get freed right away; other generations may come first).
You must dispose of the object or explicitly call Close to close the connection.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hello,
I am writing an interpreter program that should implement a parser class that uses a parse tree and then have the expressions evaluated into an evaluator class. The second option is to use a syntax called Grammar (which I was told can implement both the Parser and the Evaluator in it).
Any ideas to help me out? do you know of any URL or anywhere I can get a better idea (sort of tutorial from which I can learn) on how to implement one of these two?
Thank you in advance,
A Newbie in tha block
|
|
|
|
|
I've worked mostly with compilers, but they are not too far off from interpretive evaluators.
So...
The approach I would take is dependant upon how complex the language is. If the language is along the lines of assembler:
op parm,target
-or-
macro
Then your Grammar processor is acceptable.
The more english-like or complex the structures are, then you need to implement a parser class (validate the input, identify key tokens, etc.) then once the phrase is parsed you evaluate and execute the parsed elements.
There are 10 kinds of people in the world.
Those that read binary...
...and those who don't.
|
|
|
|
|
|
Hi,
I'm trying to create an application that, given a URL, will spider/crawl through all publicly viewable directories at the URL, and list all the files the contain in a listbox or grid of some sort. Does anyone know of any tutorials which cover this sort of spidering/crawling (preferably in C#)? - I looked, but I couldn't find anything of merit. If no one knows of any tutorials, I would appreciate any push in the right direction as to what classes might be needed.
Thanks,
Justin
|
|
|
|
|
Off the top of my head I don't know of any links that discuss this, but in reality if you break the problem down into smaller pieces, it really shouldn't be that difficult. You will need a mechanism to given a URL, extract the HTML content returned from the server. You would want to look into the HttpWebRequest class to do that. Once you had the content it's simply a matter of parsing, whether or not you tokenize the document or use regular expressions, that's up to you. Hopefully this should get you started.
- Nick Parker My Blog | My Articles
|
|
|
|
|
...and combine what Nick said with the SgmlReader[^] to read and help parse the HTML (HTML is an SGML grammar).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hello,
I built a program that reads data from an Excel Workbook and spits out Xml to be read by another program. It is written in C#, and I use Microsoft Visual Studio 2002 for development.
My question is this: where can I find information regarding the use of Microsoft's DLLs. When I compile my program, the following DLL's are placed in my program folder:
Interop.Excel.dll
Interop.Microsoft.Office.Core.dll
Interop.VBIDE.dll
I need to know if I am allowed to include these in my program, because this program is going to be sold and or licenced to people, but I obviously did not write the dll's, and I don't want Microsoft to sue me.
I also need to know what happens if someone has an older or newer version of Excel installed... will these dll's still work?
If someone could at least point me towards the answers to these questions, that would be great. Thanks!
Jeremy O
PM Logic
www.jeremyo.com
|
|
|
|
|
Yes and no. You can ship those DLLs - they do not contain any implementation. Those DLLs (assemblies) are merely RCWs (Runtime Callable Wrappers), or "interop assemblies".
The "no" part of my answer is because you're using the wrong assemblies. When possible, use the Primary Interop Assemblies (PIAs) shipped by the company (in this case, us - Microsoft). You can download the Office 2002 PIAs from http://www.microsoft.com/downloads/details.aspx?FamilyId=C41BD61E-3060-4F71-A6B4-01FEBA508E52&displaylang=en[^] and the Office 2003 PIAs are included with the Office 2003 System installations as "Developer Support" (or something similar).
You will have to chance your project references and your using statements, but the interfaces, classes, methods, properties, enumerations, and struct names should all remain the same.
The difference is that Office PIAs are "official" and signed with the corporate key, making it easier to support. If you download, extract, and follow the README file (or install these with Office 2003), in the future the PIAs are used automatically.
When possible, develop against the oldest typelibs (COM type libraries; they're used to generate RCWs) you can (without sacrificing functionality you need). When written correctly - and Office is - COM types are supported in future versions, only being deprecated when absolutely necessary (this is acheived, in part, by never changing published interfaces - always derive new interfaces with new methods, even when exposing .NET components to COM).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi all!
Is it possible to change the color of Text in the Visual-Studio Editor? If it is, how can I do this? (I'm working with c#)
Any links, tutorials, tips?
Thanks in advance.
Christian
|
|
|
|
|
If you look at the object model for the EnvDTE object, you might notice the ColorableItems property/object. Read about it in your VS.NET help documentation or online in the MSDN Library[^].
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Ok, so I have a PictureBox on my form named pctInternet. It has the following code associated with it:
string imageLocation = @"C:\mypicture.jpg";<br />
Bitmap bmp = new Bitmap(imageLocation);<br />
pctInternet.Image = bmp;
Now, I just want my PictureBox to display the picture and CLOSE the actual "mypicture.jpg" file, but for some reason whenever I try to delete the "mypicture.jpg" file while my app is running, it errors and says "File is in use."
How do I fix this? What line of code am I missing?
|
|
|
|
|
Because the file is in use. What you need to do is clonse the Bitmap and then dispose it:
using (Bitmap bmp = new Bitmap(imageLocation))
{
pctInternet.Image = (Bitmap)bmp.Clone();
} It's good to use the using block statement for IDisposable implementation because it ensures that objects are disposed even if an exception occurs (it compiles to a try-finally block).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
That doesn't work though. Another work around might be the following:
string loc = @"C:\image1.gif";
using(Bitmap bmp = new Bitmap(loc))
{
using(Graphics g = Graphics.FromHwnd(this.Handle))
{
g.DrawImage(bmp, 5, 5);
}
}
- Nick Parker My Blog | My Articles
|
|
|
|
|
When I set the user account to be disabled or change password at next logon Properties["userAccountControl"].Value always returned ADS_UF_NORMAL_ACCOUNT (512).
Any ideas?
|
|
|
|
|
And this has to do with C# how?
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
If you want to disable the account set your userAccountControl value to 514 (0x202).
- Nick Parker My Blog | My Articles
|
|
|
|
|
I want to see which accounts are locked out.
|
|
|
|
|
If you want to check a particular account, the following will work:
string path = "LDAP://Blah=blah,Blah=blah";
DirectoryEntry de = new DirectoryEntry(path);
int val = Convert.ToInt32(de.Properties["userAccountControl"][0];
if((val & 0x202) == 0)
MessageBox.Show("Account is disabled");
- Nick Parker My Blog | My Articles
|
|
|
|
|
It works if user account is disabled, but does not work if account is locked out ((Convert.ToInt32(de.Properties["userAccountControl"].Value & ADS_UF_LOCKOUT) == ADS_UF_LOCKOUT)
|
|
|
|
|
Zackmac wrote:
but does not work if account is locked out ((Convert.ToInt32(de.Properties["userAccountControl"].Value & ADS_UF_LOCKOUT) == ADS_UF_LOCKOUT)
You need to check if your add operation equals 0, not 0x0010 - 16 (ADS_UF_LOCKOUT). Try this for a lockout checking:
string path = "LDAP://Blah=blah,Blah=blah";
DirectoryEntry de = new DirectoryEntry(path);
int val = Convert.ToInt32(de.Properties["userAccountControl"][0];
if((val & 0x210) == 0)
MessageBox.Show("Account is locked out");
- Nick Parker My Blog | My Articles
|
|
|
|
|
You don't understand me. Problem is userAccountControl value is not reflected when account is locked, but the userAccountControl value changes when the user account is disabled.
|
|
|
|