|
For one, you could eliminate the need to define your own protocol if you use XML Web Services or .NET Remoting. A DataSet will be serialized to XML automatically by the Web Services and .NET Remoting serialization (XML Serialization and Runtime Serialization, respectively).
If you want to transfer something immediately, then do so. I guess I don't see what the problem is. If your client/server communication is two way (like you're own socket programming), then just send the data to the client.
For a DataSet , it's really quite easy. Create a new MemoryStream and call DataSet.WriteXml passing the MemoryStream . Now you can read the contents of the MemoryStream into a byte[] array. You could also use a StringWriter then encode the resulting string using the Encoding of your choice to get the bytes and send them down the wire.
If you're using XML Web Services or .NET Remoting via an HTTP channel, then communications is - by design - client-request/server-response only. A server cannot send the client something unless the client requests it, since the client establishes the connection. If you use .NET Remoting using an TCP channel (or a custom transport sink, which then it depends on the implementation), you can send data from the server to the client if the client has registered a sponsor with the server (or used some proprietary means of the server keeping a reference to the client).
If you need more help, please be more specific.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I've been putting the ArrayList to store instances of forms to good use. However the limitation of not being able to change the collection means its not really the ideal thing I'm looking for.
Specifically, I'm looking for a way to access instances of a form / class, and be able to change the underlying collection.
Thanks!
|
|
|
|
|
You can add, remove, and re-reference items in the ArrayList , which, BTW, is used extensively behind the scenes of all your favorite list and collection classes. Where do you get the idea it can't be changed?
If you're having a specific problem, please respond and be specific about what the problem is.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Maybe I misunderstood what you meant in your other response to the windows forms question.
> Using a foreach loop is easy - just be sure you don't change the underlying collection.
I am using a foreach loop to iterate through the collection of instances, and removing them in the destructor (instances.Remove(this)).
However that brings up some InvalidOperation exceptions regarding the collection having been changed. I thought that meant that you couldn't change the underlying collection.
|
|
|
|
|
Don't use the destructor. Override Dispose(bool) - which VS.NET does for you - and remove it there. If anything changes the collection you are currently enumerating in any thread, an exception will be thrown. The collection cannot change - no matter how it is changed - while enumerating. Period.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I strongly suspected it was an issue related to accessing an instance that has been changed. I read up about the ArrayList class, and found the problem was that I was iterating though an altered list (The foreach loop was doing the altering).
To prevent that, when the correct instance is found, the loop is broken.
|
|
|
|
|
Dear gurus,
How do you insert the single-quote character into text columns of database tables, especially with ORACLE? For example,
"INSERT INTO PRODUCT (Prod_Name, Prod_ID) VALUES ('Uncle Ken's Donuts', 1001)"
I am having this kind of problems @work...
Thanks with a million $
Khang
|
|
|
|
|
Use a double apostrophe in your string literal:
e.g. 'The main street in my home town is called Prince''s Street'
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
The Second EuroCPian Event will be in Brussels on the 4th of September
Can't manage to P/Invoke that Win32 API in .NET? Why not do interop the wiki way!
My Blog
|
|
|
|
|
First, we've said this in the Forums dozens and dozens of times:
Use parameterized queries! It doesn't have to be a stored procedure, but use SqlParameters! That way, you don't have to worry about escaping your single quoted data at all. The SqlParameter class takes care of all of that for you.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
and will be faster too. Since the query will always be the same db server can cache the query plan and just use different values next time you call the query.
|
|
|
|
|
|
I am developing an Internet Explorer bar, much like the Search sidebar. I need to make Web requests, and generally I use mshtml.HTMLDocument for that when I'm retrieving Web pages, but occasionally I need to make a lightweight connection to a Web service, and for that I use WebRequest.
The problem is that one of my clients uses an authenticating Web proxy. Apparently they need to login once with the username/password at the beginning of an Internet Explorer session, and from then on they are authenticated. When I'm using HTMLDocument, I don't have any trouble with the proxy as I suspect IE is using the same code. However, when I use WebRequest, I get proxy authentication errors, so I know that I have to authenticate with the proxy.
With some testing, I learned that
<code>
System.Net.WebProxy proxy = System.Net.WebProxy.GetDefaultProxy();
proxy.Credentials = System.Net.CredentialCache.DefaultCredentials;
System.Net.GlobalProxySelection.Select = proxy;
System.Net.WebRequest wr = System.Net.WebRequest.Create("http://www...");
</code>
does not work, but
<code>
System.Net.WebProxy proxy = System.Net.WebProxy.GetDefaultProxy();
proxy.Credentials = new System.Net.NetworkCredential(user, password);
System.Net.GlobalProxySelection.Select = proxy;
System.Net.WebRequest wr = System.Net.WebRequest.Create("http://www...");
does.
That is, .NET does not automatically detect the user/password pair which was inputted at the beginning of the IE session. The proxy settings seem to be static as GetDefaultProxy() returns the correct proxy address and port, but the credentials are empty. Furthermore, I don't know how I would be able to establish Web connections under the current proxy session within .NET. Since I expect a possible enterprise-wide deployment with this client, and possibly other enterprises, I would like to be able to use the proxy without having to request and maintain the user's proxy password (securely).
Does anyone know a way to go about this? If I have to poke around IE's registry settings to get this information, I'll happily do so, although it would be nicer to simply use .NET framework methods (e.g. GetDefaultProxy()). I've been poking around on this topic off and on for the past week or two, and I'm fairly stumped. It seems I may have to request the authentication information during the installation process, but that seems less than ideal.
Thanks!
Arun
|
|
|
|
|
.NET may not - as you've notice - grab the credentials for the authenticating proxy, nor does WebProxy.GetDefaultProxy pick-up dynamic proxy settings (a la script, as many networks use). The default credential cache only works for NTLM, negotiate, and Kerberos authentication. Which does the proxy use? Also keep in mind that any older proxies - like those that may redirect to a login page - are not supported.
As far as IE's credentials it grabs for proxy authentication, this information is not stored in shared memory. While your .NET control runs within the IE process, it may not have access to the security context. Only a little testing will tell for sure.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I asked my client to talk to his IT. This is the response:
If you are talking about our outgoing proxies used by internal browsers to access the Internet, we use NetApp proxies. The authentication methods allowed are NTLM and Basic Auth. Let me know if this is or is not what you are looking for.
Is that consistent with your comments above? The default credential cache didn't seem to work in my tests.
|
|
|
|
|
The big question is how the browsers are configured. Most corporate networks these days seem to use automatic configuration through a script like I mentioned before. WebProxy.GetDefaultProxy will not pick this information up automatically, so you would have to configure these settings yourself and set the instance of your WebProxy to the HttpWebRequest.Proxy property. If you read about the HttpWebRequest.Proxy property in the .NET Framework SDK, you will find more information.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Ugh, sorry about that nasty formatting. Let me try again:
I asked my client to talk to his IT. This is the response:
If you are talking about our outgoing proxies used by internal
browsers to access the Internet, we use NetApp proxies. The
authentication methods allowed are NTLM and Basic Auth. Let me
know if this is or is not what you are looking for.
Is that consistent with your comments above? The default credential cache didn't seem to work in my tests.
|
|
|
|
|
I'm getting a "The process cannot access the file myfile.bak because it is being used by another process." exception for the following code:
<br />
if (File.Exists("myfile.xml"))<br />
{<br />
if (File.Exists("myfile.bak"))<br />
File.Delete("myfile.bak");<br />
<br />
File.Move("myfile.xml", "myfile.bak");<br />
}<br />
The exception is happening on the File.Move() operation. Unfortunately the File class does not have a flush() or close() method that I could use. Can anyone suggest anything else ?
|
|
|
|
|
Try this:
if (File.Exists("myfile.xml"))
{
if (File.Exists("myfile.bak"))
File.Delete("myfile.bak");
Application.DoEvents();
System.Threading.Thread.Sleep(500);
File.Move("myfile.xml", "myfile.bak");
}
It may let the operating system perform the function before you attempt to move the file. Another option is to just do the move without doing the delete.
______________________________
The Tao gave birth to machine language.
Machine language gave birth to the assembler.
The assembler gave birth to ten thousand languages.
Each language has its purpose, however humble.
Each language expresses the Yin and Yang of software.
Each language has its place within the Tao.
Beauty exists because we give a name to C#.
Bad exists because we give a name to COBOL.
|
|
|
|
|
Thanks for the quick reply but unfortunately no dice. I still get the exception even after I started playing around with the time interval for the thread. I suspect the problem is inside File.Move(); for some reason that operation will not create "myfile.bak".
|
|
|
|
|
Did you try my second suggestion to do the File.Move WITHOUT the File.Delete ?
______________________________
The Tao gave birth to machine language.
Machine language gave birth to the assembler.
The assembler gave birth to ten thousand languages.
Each language has its purpose, however humble.
Each language expresses the Yin and Yang of software.
Each language has its place within the Tao.
Beauty exists because we give a name to C#.
Bad exists because we give a name to COBOL.
|
|
|
|
|
Yeah I did. I got the same exception. After tracing through it with the debugger the exception is thrown by File.Move(). I just don't know why. Is it a problem that I'm trying to rename my file to something that doesn't exist ?
|
|
|
|
|
No, you would get an exception if the file DID exist, as the method documentation states rather clearly.
It's possible it's not you using the file, either. The exception message states that the file is in use by another process. That could be use, or it could be another process. Make sure nothing else is using the file.
I've never had any problems deleting and moving files in two fell, sequential swoops. Some process - yours or not - is also using the file.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Here's the real kicker; the file does not exist. MyFile.bak does not exist on the hard drive so no other process can access it (I've also verified this by using SysInternal's handle program see what process is using what file and MyFile.bak was not in the list as expected).
|
|
|
|
|
The problem may also be that your SOURCE file is in use, not the destination. If you app has just written the .XML file, make sure that it was .Flush ed, .Close ed, and then the FileStream object .Dispose ed. This will release the unmanaged file handle in use by the FileStream object and release your file so you can rename it.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I've been testing this problem and I came to the conclusion that it is specific to my machine only. When the code executes on someone else's machine it works fine. Thanks for all who replied trying to help me fix this problem.
|
|
|
|