Jump to content
Xtreme .Net Talk

karlhaak

Members
  • Posts

    5
  • Joined

  • Last visited

Everything posted by karlhaak

  1. To whom it may concern. A few days ago I came across the following behavior. If a html table element has the attribute background the code behind the page will be called twice. I had inherited this page by another developer and striped it down until I came out with the following extract. Of course there is no attribute background for table an you can just ommit it. This will also stop the code from being called twice. Hope this will save someone else valuable time. I looked for explanations on the web but could not find any. regards Karl Haak http://www.karlhaak.de <!doctype html public "-//w3c//dtd html 4.01 transitional//en"> <HTML> <HEAD> <title id="lblMarketplace">eMarketplace</title> </HEAD> <body> <table background="#000000"> </table> </body> </HTML>
  2. Quick suggestions for: Compiler Error Message: BC30149 Hello Aric, I cannot see any problem at first glance. Here are some quick things I would like to check. 1) If you programm with visual studio, it will mark the class as invalid if not all declared interfaces have been implemented. Can you check that. 2) Put the class in an extra file. 3) check if the namespace Imports System.Security.Cryptography.X509Certificates has been imported. 4) check if the namespace Imports System.Net has been imported. hope one of these will help Karl
  3. connection closed on webrequest Microsoft article I finally found the Microsoft article that applies to the problem. It can be found under the following location http://support.microsoft.com/default.aspx?scid=kb%3Ben-us%3B819450 There is also some good advice in Jan Tielens Blog Hope this will help someone who stumbles over the same problem. Karl
  4. Have you considerd to use something like this? You can dynamically create colums for a datagrid on the base of some DataTable. The boundColumn object has plenty of other options for display. There is also the HyperLinkColumn which allows you to create hyerlink columns as well. Protected g As DataGrid Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim dt As DataTable = getDataFromDatabase() Dim dc As DataColumn For Each dc In dt.Columns Dim dbc As BoundColumn = New BoundColumn dbc.DataField = dc.ColumnName dbc.HeaderText = dc.ColumnName g.Columns.Add(dbc) Next End Sub
  5. connection closed on webrequest Thank you very much for your post here. The option with keepAlive=false works excellent for me. I was experiencing the following behavior. I was writing a windows service that would connect to a website, post some data to get a response. Everything worked fine when I ran the component as a console Application in Debug mode on my machine . Once installed as a service every second request failed. I had to fight with an unvalid certificate for ssl, username, password and a proxyserver which gave me plenty of options to look for. I finally tried the keepAlive option and everything works fine. I still do not understand the influence of this parameter on the failure of the connection every second time and would be interested in any ideas. The environment I am working in is Windows 2000 with .NET 1.0. I created an abstract of my solution as a coding example. Hope this will safe some time for somebody else. Karl Imports System.IO Imports System.Text Imports System.Threading Imports System.Net Imports System.Text.Encoding Imports System.Security.Cryptography.X509Certificates Public Class MyCertificateValidation Implements System.Net.ICertificatePolicy 'This class handles problems with certificates if ssl (https) is used Public Function CheckValidationResult(ByVal srvPoint As ServicePoint, _ ByVal cert As X509Certificate, ByVal request As WebRequest, ByVal problem As Integer) _ As Boolean Implements ICertificatePolicy.CheckValidationResult Return True ' Accept all certificates End Function End Class Public Class RequestState Public request As WebRequest = Nothing Public requestDocument As String End Class Public Class HTMLRequest 'Handler to synchronise with main thread again Public allDone As New ManualResetEvent(False) Private _requestDocument As String = "Text to send" Private _responseDocument As String Private _web As Net.HttpWebRequest Private Sub ReadCallback(ByVal asynchronousResult As IAsyncResult) 'Get the information to pass on from the Async Object Dim myRequestState As RequestState = CType(asynchronousResult.AsyncState, RequestState) Dim myWebRequest2 As WebRequest = myRequestState.request Dim requestDocument As String = myRequestState.requestDocument 'Get the stream to write the request to Dim streamResponse As Stream = myWebRequest2.EndGetRequestStream(asynchronousResult) Dim bytArray() As Byte = System.Text.Encoding.ASCII.GetBytes(requestDocument) streamResponse.Write(bytArray, 0, requestDocument.Length) streamResponse.Close() 'Tell the main thread that writing to stream is complete allDone.Set() End Sub Public Sub retrieve() Dim bytOutArray() As Byte Dim objWebResponse As Net.WebResponse = _web.GetResponse Dim objStream As IO.StreamReader objStream = New IO.StreamReader(objWebResponse.GetResponseStream(), System.Text.ASCIIEncoding.ASCII) _responseDocument = objStream.ReadToEnd() 'close all streams objWebResponse.Close() objStream.Close() End Sub Public Sub send() 'Prepare Object to pass into asynchron call Dim myRequestState As New RequestState myRequestState.request = _web myRequestState.requestDocument = _requestDocument Dim r As IAsyncResult = CType(_web.BeginGetRequestStream(AddressOf ReadCallback, myRequestState), IAsyncResult) 'Wait till asychrone is done ## allDone.Set() ## allDone.WaitOne() End Sub Public Sub getRequest() 'Configure connection 'in case of problem with certificate ServicePointManager.CertificatePolicy = New MyCertificateValidation 'Create request object _web = CType(WebRequest.Create("https://www.somedomain.com"), HttpWebRequest) With _web .ContentType = "application/x-www-form-urlencoded" .Method = "POST" .KeepAlive = False .ContentLength = _requestDocument.Length .Timeout = 10000 'in case of proxyserver .Proxy = New WebProxy("xxx.proxyserver.com", 8080) 'in case of required password Dim cache As CredentialCache = New CredentialCache cache.Add(New Uri("https://www.somedomain.com/"), "Basic", New NetworkCredential("Username", "password")) .Credentials = cache End With send() 'send the request retrieve() 'get the data End Sub End Class
×
×
  • Create New...