Last post Mar 04, 2009 04:53 AM by Wolfie
Mar 03, 2009 02:10 AM|Wolfie|LINK
An SMS service I use normally works well by doing a WebClient.UploadValues(smsURI, "post", smsPostInfo) in ASP.Net.
A situation occured where this service had a critical error and instead of returning aprox. 200 bytes of info it normally does, it returned some huge amount of data causing the statement (highlighted below) to fail with "System.OutOfMemoryException".
The actual real problem is with the SMS service provider and they are fixing the problem. But, I wanted my call to fail elegantly rather than cause an OutOfMemory exception. In investigating a means to achieve this, I ran severly out of options and was hoping
someone may give me a pointer.
Dim smsWebClient As New WebClient()
Dim smsPostInfo As New NameValueCollection()
'-- I initialize the post/value collection and set the smsURI
Dim responseArray As Byte() = smsWebClient.UploadValues(smsURI, "POST", smsPostInfo)
Dim responseStr As String = Encoding.ASCII.GetString(responseArray)
'-- more code interpreting the return string
Catch webExcept As WebException
'-- exception code - except it does not trap System.OutOfMemoryException
So, here to my question:
Since I only need about 200 bytes from the WebClient.UploadValues no matter what it returns, how do I limit what it returns?
Byte() does not allow any arguments to limit what it receives.
WebClient.UploadValues does not accept any arguments to limit the output.
It is a streaming output.
Any pointers, suggestions and tips are welcome.
Mar 03, 2009 09:09 AM|DkUltra|LINK
Would something like this work
Hope this helps
Mar 03, 2009 10:30 AM|Wolfie|LINK
Thank you for your innovative suggestion. But, alas, smsWebClient.UploadValues requires a Byte Array.
Here's what the compiler reports:
BC30332: Value of type '1-dimensional array of Byte' cannot be converted to '1-dimensional array of Char' because 'Byte' is not derived from 'Char'
Appreciate your response, though.
Mar 03, 2009 03:01 PM|DkUltra|LINK
Is Useing c# an option ? what version of .net?
Mar 04, 2009 04:53 AM|Wolfie|LINK
I am presuming from your question that it would be possible in C#.
I would have prefered not to since the whole app is in VB. But, I guess, one could write a class in C# to do the WebClient bit and just use this class in the VB code.
Using ver 2.0 of .Net.