简介
访问的GAL(全局地址列表)从Web应用程序的信息,这可能吗?显然,是的!有几篇文章在网络上列出了不同的方法,这样做的。让我们来看看详细的方法之一。背景
有时候,会有一些要求,从Web应用程序访问微软Exchange属性。访问全局地址列表是其中之一。有三种不同的方式来实现。NET Web应用程序内的Outlook联系人。 本文介绍了简短的所有三个。
我的情况下,使用{A}发现的GAL条目的方式。在OWA称为GalFind一个命令,这是用来寻找有限的领域从GAL。在URL的查询字符串,GalFind一般语法是:http://YourCompanyExchangeServer/public/?Cmd=galfind&fn=rajga
这个请求的响应,其中包含所有的GAL条目的第一个名字quot; rajgaquot; {A2}文章描述了所有可能的搜索参数。在这篇文章中,我试图结合的方法,并提供了一个详细的解决方案,在C#编写的。NET。使用代码
的GAL条目可以查询使用OWA中GalFind的命令。如果我们一个简单的HttpWebRequest发送的URL quot; http://YourCompanyExchangeServer/public/?Cmd=galfindamp; FN = rajgaquot;和有效的网络凭据,我们希望一个包含匹配的名单。但是,响应将一个HTML页面,有一个地方的持有人输入凭据,因为服务器是期待一个有效的身份验证cookie。
因此,提出这一要求的有效的,我们需要一个有效的身份验证cookie与请求一起附加。下面的代码显示了一个发送的HttpWebRequest,找到的第一个名字匹配的例子。{C}
粗体显示的代码是用来获取身份验证cookie。这种方法使用WebDAV的样品,在{A3}文章中调用owaauth.dll身份验证cookie。方法如下所示:private CookieCollection GetOWAAuthCookies(string server, NetworkCredential credentials)
{
string authURI = string.Format("{0}/exchweb/bin/auth/owaauth.dll",
server, credentials.UserName);
byte[] bytes =
Encoding.UTF8.GetBytes(string.Format("destination={0}/exchange/" +
"{1}&username={2}\\{1}&password={3}",
server, credentials.UserName, credentials.Domain,
credentials.Password));
HttpWebRequest request = WebRequest.Create(authURI) as HttpWebRequest;
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencode";
request.CookieContainer = new CookieContainer();
request.ContentLength = bytes.Length;
request.AllowAutoRedirect = false;
using (Stream requestStream = request.GetRequestStream())
requestStream.Write(bytes, 0, bytes.Length);
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
CookieCollection _oCookieCollection = response.Cookies;
response.Close();
return _oCookieCollection;
}
}
执行此代码将返回GAL条目匹配的第一个名字,同样可以为姓氏,显示名称,别名以及实施。兴趣点
最初,在我的_oHttpWebRequest对象,我没有设置UserAgent属性。 _oHttpResponse对象返回我一大堆的HTML作为响应。然后,设置的UserAgent"Mozilla/4.0(相容; MSIE 6.0;的Windows NT 5.1; SV1; NET CLR 1.1.4322;的。NET CLR 2.0.50727; InfoPath.1)"后,我得到了有效的XML响应。