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
Expand|Select|Wrap|Line Numbers
- 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
SW = New StreamWriter(Request.GetRequestStream())
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 ICertificatePolicy 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