27 de março de 2011

Exchange Web Services (Instanciar o Serviço) passando o ISA

Em ambientes LIve@edu muitas vezes queremos “puxar” para a nossa aplicação a informação contida no Exchange On-line, para que tal aconteça li muito acerca de Autodiscovery para aqui e Autodiscovery para ali. O problema principal é que quando estamos na nossa Escola/Empresa, e visto os Domínios estarem repartidos na Cloud e na Empresa o mesmo não vai funcionar porque não resolve de dentro, ou seja não passa no ISA, mas para passar no ISA então há que esperar que tal aconteça, e tempo é dinheiro.

 

Tipicamente passa-se o seguinte:

 

This Error event indicates that the Microsoft® Exchange Autodiscover service could not discover the Exchange Availability service that is running in a remote Active Directory® directory service forest. The Exchange Autodiscover service that runs on a Front End server that is running Exchange Server 2007 (also known as Exchange Client Access server) is a Web service that locates a mailbox. The Exchange Availability service is also a Web service that retrieves the Schedule+ Free Busy and Out-of-Office (OOF) data for that specific mailbox. This event may occur when an Exchange 2007 Client Access server and user mailbox are in different Active Directory forests. Because the Exchange Autodiscover service cannot directly connect to a mailbox that resides in a remote Active Directory forest, it requests that the Exchange Availability service that is running in the remote Active Directory forest retrieve the requested information locally.

 

CORRECÇÃO

Vou corrigir esta parte porque esta solução não é suportada pela Microsoft e pode gerar erro no Exchange Online INTERNAL SERVER ERROR, aqui vai a solução final.

A TER EM ATENÇÃO

As definições de PROXY são a da tua máquina host de domínio não de uma ligação de VM

 

A Solução que eu encontrei foi resolver o Autodiscovery de fora e apanhar o Link, sendo assim já podemos instanciar o Serviço desta forma, para o fazeres basta invocares o método GetService().Xpto

Tens de adicionar a referencia ao teu projecto: Microsoft.Exchange.WebServices

 

/// <summary>
/// Gets the service.
/// </summary>
/// <returns></returns>
public static ExchangeService GetService()
{
// Get User and Pass for Super User Live@Edu
string sUser = GetUrl.sUser;
string sPass = GetUrl.sPass;

// Create the binding.

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010)
{ /* Define credentials.*/
Credentials = new WebCredentials(sUser, sPass),
Url = new Uri("https://OTeuServerNaCloud.outlook.com/EWS/Exchange.asmx")
};
return service;
}



EXEMPLO 




Credentials = new NetworkCredential(UserXPTO, PassXPTO, Microsoft)



Código Complero




public static ExchangeService GetBinding()
{
// Create the binding.
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
//Proxy
IWebProxy proxy = new WebProxy(GetUrl.ProxyAddress, true)
{
Credentials = new NetworkCredential(GetUrl.ProxyUser, GetUrl.ProxyPass,
GetUrl.ProxyDomain)
};

WebRequest.DefaultWebProxy = proxy;
service.Credentials = new WebCredentials("admin@dominio.pt", "999999");

try
{
// Use the AutodiscoverUrl method to locate the service endpoint.
service.AutodiscoverUrl("admin@dominio.pt", RedirectionUrlValidationCallback);
}
catch (AutodiscoverRemoteException ex)
{
Console.WriteLine("Exception thrown: " + ex.Error.Message);
}
return service;
}

static bool RedirectionUrlValidationCallback(String redirectionUrl)
{
// Perform validation.
// Validation is developer dependent to ensure a safe redirect.
return true;
}

Sem comentários:

Enviar um comentário

Like