EWS: NetworkCredential is not compatible with ExchangeCredentials in F #

I like to use the Microsoft.Exchange.WebService API:

C # works great

ExchangeService service = new ExchangeService(userData.Version); service.Credentials = new NetworkCredential(userData.EmailAddress, userData.Password); 

F # gives an error: type "NetworkCredential" is incompatible with "ExchangeCredential"

 open System open Microsoft.Exchange.WebServices.Data open System.Net [<EntryPoint>] let main argv = let connectToService userData = let service = new ExchangeService(userData.Version) do service.Credentials <- new NetworkCredential(userData.EmailAddress, userData.Password) service.Url <- userData.AutodicoverUrl 0 

I thought this had something to do with the implicit conversion that is defined in the C # API. so I tried (:>) and downcast (:?>). I tried to do this explicite (new NetworkCredential ...: ExchangeCredentials), and I checked the reference dlls as I used in C # nuget directly and in F # paket. Both are tested in VS 2015. In C # it is .Net 4.5.2 and in F # too if this is the right way to find it in app.config

  <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" /> 

And I guess using WebCredentials is not the right way. I want to use SecureString, not a string, but if it works in C #. Therefore, it is more likely that I did something wrong with the F # syntax that I would like to understand.

+8
type-systems f # exchange-server exchangewebservices
source share
1 answer

As you noticed, ExchangeCredentials defines an implicit conversion from NetworkCredentials to ExchangeCredentials , so your code functions correctly in C #. Note that there is no inheritance relationship between these two things, so you cannot use the upcast ( :> ) and downcast ( :?> ) Operators.

Implicit conversions appear in F # as a static member called op_Implicit .

 let connectToService userData = let service = new ExchangeService(userData.Version) service.Credentials <- NetworkCredential(userData.EmailAddress, userData.Password) |> ExchangeCredentials.op_Implicit // call implicit conversion service.Url <- userData.AutodicoverUrl 
+7
source share

All Articles