connecting to exchange server 2003 from vb.net


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: connecting to exchange server 2003 from vb.net

  1. #1
    Join Date
    Sep 2006
    Posts
    1

    connecting to exchange server 2003 from vb.net

    Hi All,

    I have been trying to connect to Exchange server 2003 from VB.NET.I have tried out some code.But it throws me Login Timeout(440) error.Here is the code:

    Imports System.Net
    Imports System.IO
    Imports System
    Imports System.Xml
    Imports System.Text.RegularExpressions
    Imports System.Net.HttpWebRequest
    Module Module1
    Sub Main()
    Dim strServerName As String = "servername"
    Dim strDomain As String = "domain"
    Dim strUserID As String = "userID"
    Dim strPassword As String = "password"
    ' TODO: Replace with the URL of an object on Exchange Server
    Dim sUri As String = "https://servername/exchange/userID/inbox/"
    Dim myUri As System.Uri = New System.Uri(sUri)
    'Dim HttpWRequest As HttpWebRequest = WebRequest.Create(myUri)
    Dim sQuery As String
    ' TODO: Replace with appropriate user credential
    Dim myCred As NetworkCredential = New NetworkCredential("domain\userID", "password")
    Dim MyCredentialCache As CredentialCache = New CredentialCache()
    MyCredentialCache.Add(myUri, "Basic", myCred)
    'HttpWRequest.Credentials = MyCredentialCache
    ' Create our Web request object.
    Dim PROPPATCHRequest As HttpWebRequest
    PROPPATCHRequest = CType(System.Net.HttpWebRequest.Create(myUri), System.Net.HttpWebRequest)
    ' Authenticate to OWA. Assign the returned cookies to a string.
    Dim strReusableCookies As String
    strReusableCookies = AuthenticateSecureOWA(strServerName, strDomain, strUserID, strPassword)
    ' Add the cookie set that is obtained after OWA authentication to our request header.
    PROPPATCHRequest.Headers.Add("Cookie", strReusableCookies)
    PROPPATCHRequest.ContentType = "text/xml"
    PROPPATCHRequest.KeepAlive = False
    PROPPATCHRequest.AllowAutoRedirect = False


    'Specify the PROPPATCH method.
    PROPPATCHRequest.Method = "GET"
    ' we need to store the data into a byte array
    Dim ByteQuery() As Byte = System.Text.Encoding.ASCII.GetBytes(sQuery)
    PROPPATCHRequest.ContentLength = ByteQuery.Length
    Try
    Dim QueryStream As Stream = PROPPATCHRequest.GetRequestStream()
    ' write the data to be posted to the Request Stream
    QueryStream.Write(ByteQuery, 0, ByteQuery.Length)
    QueryStream.Close()
    Catch ex As Exception
    MsgBox("Exception: " + ex.Message)
    End Try
    ' Send Request and Get Response
    PROPPATCHRequest = CType(System.Net.HttpWebRequest.Create(myUri), System.Net.HttpWebRequest)

    Dim HttpWResponse As HttpWebResponse = PROPPATCHRequest.GetResponse()
    ' Get Status and Headers
    Dim iStatCode As Integer = HttpWResponse.StatusCode
    Dim sStatus As String = iStatCode.ToString()
    Console.WriteLine("Status: {0} {1}", sStatus, HttpWResponse.StatusDescription.ToString())
    Console.WriteLine("Request Headers:")
    Console.WriteLine(PROPPATCHRequest.Headers.ToString())
    Console.WriteLine("Response Headers:")
    Console.WriteLine(HttpWResponse.Headers.ToString())
    ' Get Response Stream
    Dim strm As Stream = HttpWResponse.GetResponseStream()
    ' Read the Response Steam
    Dim sr As StreamReader = New StreamReader(strm)
    Dim sText As String = sr.ReadToEnd()
    Console.WriteLine("Response: {0}", sText)
    MsgBox("sText: " + sText)

    ' Close Stream
    strm.Close()
    ' Clean Up
    PROPPATCHRequest = Nothing
    HttpWResponse = Nothing
    MyCredentialCache = Nothing
    myCred = Nothing
    strm = Nothing
    sr = Nothing

    End Sub

    ' Code to call the Authentication:
    Private CookieJar As CookieContainer
    Private strCookies As String
    'Implementation of the Authentication to the Exchange Server 2003 server that is enabled with forms-based authentication
    Private Function AuthenticateSecureOWA(ByVal strServerName As String, ByVal strDomain As String, ByVal strUserName As String, ByVal strPassword As String) As String
    ' contains the code for authentication(couldnt post the code due to size restrictions)
    Return strCookies
    End Function

    End Module

    ----------------------------

    I guess the error is bcoz I have not authenticated using SSL certificate which the exchange server (might) expects. Can anyone please help me out?Someone tell me how to use SSL certificates in VB.NET to authenticate to the exchange server 2003.
    I've been trying these for several days .

    Thanks in advance,
    Vasanth.

  2. #2
    Join Date
    Apr 2009
    Posts
    1

    Are you still looking for solution?

    Are you still looking for solution? I have got a similar problem, could you post me full code? My mail: mniepel at komandor.sk
    My code is also too long to post it to forum.
    Thanx.

Similar Threads

  1. Replies: 0
    Last Post: 04-10-2003, 12:14 PM
  2. Replies: 0
    Last Post: 03-24-2002, 03:49 AM
  3. Exchange Server
    By RAM in forum Enterprise
    Replies: 1
    Last Post: 02-02-2002, 06:15 AM
  4. SQL Server 7 connecting to SQL Server 2000
    By Mario F. in forum Database
    Replies: 1
    Last Post: 06-02-2001, 12:10 AM
  5. Backup Exchange Server
    By Fabio Losnak in forum Enterprise
    Replies: 1
    Last Post: 05-12-2000, 04:19 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center