Re: Close OWA Connection



Hi,

After connecting to exchange, I collect the cookies as such:

----- code snippet -----
try
{
//Get server portion of uri and append Exchange auth dll
server = uri.Substring(0, uri.IndexOf("/", 8)) +
"/exchweb/bin/auth/owaauth.dll";

//Build request
request = GetRequestObject(server, "POST");
request.CookieContainer = new CookieContainer();
request.ContentType = "application/x-www-form-urlencoded";

//Prepare body of request
body =
Encoding.UTF8.GetBytes(string.Format("destination={0}&username={1}\\{2}&password={3}",
uri, credential.Domain, credential.UserName, credential.Password));

request.ContentLength = body.Length;

//Send request to server
stream = request.GetRequestStream();
stream.Write(body, 0, body.Length);
stream.Close();

//Get response
response = (HttpWebResponse)request.GetResponse();

//Check if login successful
if (response.Cookies.Count < 2) throw
new Exception("Failed to login to OWA. Be sure your domain and password are
correct.");

//Build OverLoaded Cookie Collection
CookieCollection responseCookies = new CookieCollection();

//Add cookies to this collection
responseCookies.Add(response.Cookies[0]);
responseCookies.Add(response.Cookies[1]);

//Return the cookie collection
return responseCookies;
}

----- code snippet -----

I then add these cookies into any further requests, which seems to work
fine, for a period of time. Then I start getting Timeouts. I assume this is
because my exchange session as timed-out. To get around this, I wanted to
close my exchange session (i.e logoff) after every connection I make. I
tried the code you provided, but no luck. Would I not have to include the
cookies in the HTTP request containing the ?cmd=logoff command, or is the
credential set enough info for exchange? ((that wouldn't seem very secure))

Is this the appropriate way to maintain a connection to exchange - I would
either like the timeout period on the exchange session renewed upon every
action (and a re-login when it timesout with inactivity), or preferably, the
session to be opened and closed on every request (hence never have a timeout
problem).

Also, is there a reference to what commands like \?Cmd=logoff are availabkle
with exchange server?? i have the Exchange 2003 SDK installed - but there
doesn't seem to be a whole lot in it....

I probably should mention that this is for a sharepoint (wss) web part.

Many thanks,

Nigel W

"Glen Scales [MVP]" wrote:

That error sounds like your trying to send some sort of body with you get
requestion which you shouldn't be doing the following code snippet seems to
work okay for me

using System;
using System.Net;
using System.IO;
using System.Text;
using System.Xml;

namespace ExchangeSDK.Snippets.CSharp
{
class GettingItemPropertyValuesWebDAV
{
[STAThread]
static void Main(string[] args)
{
System.Net.HttpWebRequest Request;
System.Net.WebResponse Response;
System.Net.CredentialCache MyCredentialCache;
string strSrcURI = "http://server/exchange/mailbox/?Cmd=logoff";;
string strUserName = "user";
string strPassword = "password";
string strDomain = "domain";
System.IO.Stream ResponseStream = null;
MyCredentialCache = new System.Net.CredentialCache();
MyCredentialCache.Add( new System.Uri(strSrcURI),
"Basic",
new System.Net.NetworkCredential(strUserName, strPassword, strDomain)
);


Request = (System.Net.HttpWebRequest)HttpWebRequest.Create(strSrcURI);
Request.Credentials = MyCredentialCache;
Request.Method = "GET";
Request.ContentType = "text/xml";
Response = (HttpWebResponse)Request.GetResponse();
ResponseStream = Response.GetResponseStream();
StreamReader objReader = new StreamReader(ResponseStream);
string sLine = "";
int i = 0;
while (sLine!=null)
{
i++;
sLine = objReader.ReadLine();
if (sLine!=null)
Console.WriteLine("{0}:{1}",i,sLine);
}
Console.ReadLine();

ResponseStream.Close();
Response.Close();
}

}
}

Cheers
Glen

"NgelW" <NgelW@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:B4B7BC33-B4DD-43DA-8C69-1BDE070517AA@xxxxxxxxxxxxxxxx
Thanks - I have tried to implement this as a GET call (hacked from a
function
performing a POST call), but it returns a "Cannot send a content-body with
this verb-type" error <see code snippet below>

Is there (yet again) something obvious that I am doing wrong? Also, it
suprises me a little that I don't need to use the cookies gained when I
established my connection to OWA to terminate the connection?!?

----- code snippet -----

public void BreakAuthentication(string uri)
{
//Paramters
HttpWebRequest request;
HttpWebResponse response;
byte[] body;
Stream stream;
string uriToUse;

//Update URI
uriToUse = uri.Substring(0, uri.IndexOf("/", 8)) + "/?Cmd=logoff";

//Build request
request = GetRequestObject(uriToUse, "GET");

//This is probably the problem?!? What sort of Content-Type should I
//use?
request.ContentType = "application/x-www-form-urlencoded";

//Send request to server
stream = request.GetRequestStream();
stream.Close();

//Get response
response = (HttpWebResponse)request.GetResponse();

}

---- end code snippet ----



"Glen Scales [MVP]" wrote:

Are you using Exchange 2003 is so you could just make a call to the OWA
Logoff command eg

GET /exchange/user/?Cmd=logoff

cheers
Glen
"NgelW" <NgelW@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:77572BDF-93BC-4C03-B904-264774EEE3DE@xxxxxxxxxxxxxxxx
Hi,

In a c# app, I have established a connection to OWA, and done what I
need
to
do on the exchange server, and would now like to close that connection
rather
then allowing it to time-out. Can anyone explain how this can be done?

Many thanks,

Nigel






.



Relevant Pages

  • Re: NotificationSampleWebDav-Monitor OWA Inbox
    ... when you send your authentication cookies along a request in the ... the response should also contain new cookies. ... Can you guide me how can I update the cookie with new response. ... Warning: Exiting Action with an exception: The remote server returned ...
    (microsoft.public.exchange.applications)
  • Re: Screen Scraping a Password Protected Site
    ... http traffic. ... cookies to a singleton CookieContainer and the once you have logged in ... If TypeOf request Is HttpWebRequest Then ... If TypeOf response Is HttpWebResponse Then ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Close OWA Connection
    ... requestion you make to a exchange server. ... You can adjust the timeout of cookies with certain registry keys but I would ... when you use OWA and then you can examine what the format of the request are ...
    (microsoft.public.exchange.development)
  • Re: Screen Scraping a Password Protected Site
    ... cookies to a singleton CookieContainer and the once you have logged in ... If TypeOf request Is HttpWebRequest Then ... Protected Overrides Function GetWebResponse(ByVal request As ... If TypeOf response Is HttpWebResponse Then ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Post to https using perl script
    ... It is a response status (error codes ... If the 302 status code is received in response to a request other than ... You seem to be unsure about cookies, ...
    (comp.lang.perl.misc)