HTTPS on Compact Framework

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Greg Wood
    New Member
    • Jan 2007
    • 2

    #1

    HTTPS on Compact Framework

    As a new member, I hope I am posting correctly. Bear with me if not !

    I found a posting by Earle Oxner that very closely matches the situation we are in. Sadly, there were no replies to his post, so I am asking a similar question. We have developed a .Net Compact Framework 2 forms application & deployed it on a 2 PDAs, one running Windows Mobile 2003 2nd Edition and one running Windows Mobile v5.

    The app's purpose is to POST data to an HTTPS url and the code is below
    Code:
    Public Shared Function Send(ByVal URL As String, _
            Optional ByVal PostData As String = "", _
            Optional ByVal Method As HTTPMethod = HTTPMethod.HTTP_GET, _
            Optional ByVal ContentType As String = "")
    
            Dim Request As HttpWebRequest = WebRequest.Create(URL) ' opens a connection to the URL 
            Dim Response As HttpWebResponse
            Dim SW As StreamWriter
            Dim SR As StreamReader
            Dim ResponseData As String
            Dim flag As Boolean
            ' Prepare Request Object
            Request.Method = Method.ToString().Substring(5) 'find out if it's a POST or GET.  
    
            ' Set form/post content-type if necessary
            If (Method = HTTPMethod.HTTP_POST AndAlso PostData <> "" AndAlso ContentType = "") Then
                ContentType = "application/x-www-form-urlencoded"
            End If
    
            ' Set Content-Type
            If (ContentType <> "") Then
                Request.ContentType = ContentType
                Request.ContentLength = PostData.Length
            End If
    
            flag = False 'set to false, if we instantiate SW then it will be set to true so that the Finally knows whether to kill it or not.
            ' Send Request, If Request
            If (Method = HTTPMethod.HTTP_POST) Then
                Try
                    SW = New StreamWriter(Request.GetRequestStream()) 'new stream writer to the open connection. 
                    flag = True
                    SW.Write(PostData) 'write the data to the open connection.
                Catch Ex As Exception
                    'handle any errors here; return a string to say it failed.
                    'Throw Ex'this was the default action that caused a crash.
                    Return "Failure to send"
                    Exit Function
                Finally
                    If flag Then
                        SW.Close()
                    End If
                End Try
            End If
    
            ' Receive Response
            flag = False 'reset the flag for the next block
            Try
                Response = Request.GetResponse
                SR = New StreamReader(Response.GetResponseStream())
                flag = True
                ResponseData = SR.ReadToEnd()
            Catch Wex As System.Net.WebException
                SR = New StreamReader(Wex.Response.GetResponseStream())
                ResponseData = SR.ReadToEnd()
                Throw New Exception(ResponseData)
            Finally
                If flag Then
                    SR.Close()
                End If
            End Try
    
            'we now have a response from the server, probably a positive one.
            ' need to find the phrase 'Message received successfully'
            Dim result As Integer = InStr(ResponseData, "Message received successfully", CompareMethod.Text)
            'MsgBox(result)
            If result <> 0 Then
                'it was successfull.
                Return "Success"
            Else
                Return "Failure"
            End If
    
            Return ResponseData
        End Function
    When the URL parameter is a valid http: address, the code works fine. When it is a https: address, it fails at the line
    SW = New StreamWriter(Re quest.GetReques tStream())

    We tried installing a Certificate on the PDA and offering it by addressing the same https url through Internet Explorer before then running the application. We hoped this would allow the app to use the previously-certificated connection, but it failed as before.

    Next we thought about certificating in code within the app and found a posting on Jan Tielens' Blog site suggesting this was possible. However, it turned out that the ICertificatePol icy interface could not be accessed in an app using the Compact Framework (which ours is)

    Now we are stuck ! Any help on using the Compact Framework version of VB.Net to programatically broker an HTTPS connection would be greatly appreciated
  • radcaesar
    Recognized Expert Contributor
    • Sep 2006
    • 759

    #2
    Along with enabling SSL on the Windows Mobile 2003 for Smartphone agent, you will also need to enable SSL on the Device Manager server.

    Have u done with that ?

    :)

    Comment

    • Greg Wood
      New Member
      • Jan 2007
      • 2

      #3
      Originally posted by radcaesar
      Along with enabling SSL on the Windows Mobile 2003 for Smartphone agent, you will also need to enable SSL on the Device Manager server.

      Have u done with that ?

      :)
      Hello radcaesar,

      Although we could not find any setting on the PDA's o/s that related to enabling SSL, we can make an https connection on the device when we use Internet Explorer browser, so I assume SSL is enabled and correctly configured on the server (actually an iChain server) and the PDA device itself. Problems arise when trying to make the connection using the VB.Net app rather than the browser.

      Comment

      Working...