Home All Groups Group Topic Archive Search About

Use Mapi in web service

Author
18 Oct 2007 1:48 PM
arsenmkrt
Hi. I develop an ASP.NET web service that calls COM Interop function which do
some work by MAPI (change properties of some mails in a given users mailbox)
.. The problem is when I put my web service under IIS the exception is thrown
from Mapi  it can't create profile i didn't try but co-worker says that it
doesn't call correctly even MapiInitilize(). I try to enable anonymous access
and change the anonymous user to Admin but it doesn't help. All work fine
when i use VS2005 integrated Web Server or call Web Service by giving empty
credential like this

System.Net.CredentialCache cache = new System.Net.CredentialCache();
cache.Add(new Uri(url), "NTLM", new NetworkCredential());
service.Credentials = cache;

Note that my Web Service function is calling before i use credential only
com(mapi) is throwing exceptions.
Isn't IIS anonymous user has same permissions as empty  NetworkCredential
because i am logged in from the same user? by the way i can't leave
credentials in the client because i should call this service from Mac client.
please help to understand what is the problem. Thanks a lot.

Author
18 Oct 2007 3:34 PM
Henning Krause [MVP - Exchange]
Hi,

for performance reasons, IIS does not load the user profile by default, so
the profiles are probably just not loaded into memory.

That said, MAPI is not supported under .NET because its memory management
conflicts with the .NET garbage collector. It will work most of the time but
it will yield unexpected results here and there.

You should switch the protocol over to WebDAV, CdoEx (via interop on the
Exchange server) or WebServices (if you are using Exchange 2007).

Redemption is another option (http://www.dimastr.com/redemption/).

Kind regards,
Henning Krause


Show quote
"arsenmkrt" <arsenm***@discussions.microsoft.com> wrote in message
news:3B4FDE7F-6AB0-490C-837A-80FAEE7928AC@microsoft.com...
> Hi. I develop an ASP.NET web service that calls COM Interop function which
> do
> some work by MAPI (change properties of some mails in a given users
> mailbox)
> . The problem is when I put my web service under IIS the exception is
> thrown
> from Mapi  it can't create profile i didn't try but co-worker says that it
> doesn't call correctly even MapiInitilize(). I try to enable anonymous
> access
> and change the anonymous user to Admin but it doesn't help. All work fine
> when i use VS2005 integrated Web Server or call Web Service by giving
> empty
> credential like this
>
> System.Net.CredentialCache cache = new System.Net.CredentialCache();
> cache.Add(new Uri(url), "NTLM", new NetworkCredential());
> service.Credentials = cache;
>
> Note that my Web Service function is calling before i use credential only
> com(mapi) is throwing exceptions.
> Isn't IIS anonymous user has same permissions as empty  NetworkCredential
> because i am logged in from the same user? by the way i can't leave
> credentials in the client because i should call this service from Mac
> client.
> please help to understand what is the problem. Thanks a lot.
>
Author
18 Oct 2007 4:43 PM
Dan Mitchell
"Henning Krause [MVP - Exchange]" <newsgroups_rem***@this.infinitec.de>
wrote in news:#mi6kxZEIHA.4140@TK2MSFTNGP03.phx.gbl:
> That said, MAPI is not supported under .NET because its memory
> management conflicts with the .NET garbage collector. It will work
> most of the time but it will yield unexpected results here and there.

See

http://blogs.msdn.com/mstehle/archive/2007/10/03/fyi-why-are-mapi-and-cdo-
1-21-not-supported-in-managed-net-code.aspx

for the details of this.

-- dan
Author
19 Oct 2007 5:48 AM
arsenmkrt
Show quote
"Dan Mitchell" wrote:

> "Henning Krause [MVP - Exchange]" <newsgroups_rem***@this.infinitec.de>
> wrote in news:#mi6kxZEIHA.4140@TK2MSFTNGP03.phx.gbl:
> > That said, MAPI is not supported under .NET because its memory
> > management conflicts with the .NET garbage collector. It will work
> > most of the time but it will yield unexpected results here and there.
>
>  See
>
> http://blogs.msdn.com/mstehle/archive/2007/10/03/fyi-why-are-mapi-and-cdo-
> 1-21-not-supported-in-managed-net-code.aspx
>
>  for the details of this.
>
>  -- dan
>
Sorry, but I didn't use MAPI in .NET. My Web service call ATL COM dll (was
write in C++) and this ATL COM dll WORKING WITH MAPI!!! Web service call ATL
COM dll normaly but I think DLL canot load MAPI32.dll for initialize.... All
problem only in it!!! What can I do?
Author
19 Oct 2007 3:16 PM
Dan Mitchell
=?Utf-8?B?YXJzZW5ta3J0?= <arsenm***@discussions.microsoft.com> wrote in
news:E4162A31-A664-47A9-B27C-E4C2D328CEAF@microsoft.com:
> Sorry, but I didn't use MAPI in .NET. My Web service call ATL COM dll
> (was write in C++) and this ATL COM dll WORKING WITH MAPI!!!

Then you're trying to call ExMAPI code from a .Net process -- the DLL
gets loaded into the process space of your main app, which is a .Net app.

If your code was a standard NT service which listened on port 80 and
handled web requests without using the .Net runtime, it (hopefully) would
be able to call the DLL okay, because the main process wouldn't be .Net
any more. On the other hand, you'd have to write all the web request
handling code yourself, which is probably more trouble than it's worth..

-- dan
Author
19 Oct 2007 5:48 AM
arsenmkrt
Show quote
"Henning Krause [MVP - Exchange]" wrote:

> Hi,
>
> for performance reasons, IIS does not load the user profile by default, so
> the profiles are probably just not loaded into memory.
>
> That said, MAPI is not supported under .NET because its memory management
> conflicts with the .NET garbage collector. It will work most of the time but
> it will yield unexpected results here and there.
>
> You should switch the protocol over to WebDAV, CdoEx (via interop on the
> Exchange server) or WebServices (if you are using Exchange 2007).
>
> Redemption is another option (http://www.dimastr.com/redemption/).
>
> Kind regards,
> Henning Krause
>
>
> "arsenmkrt" <arsenm***@discussions.microsoft.com> wrote in message
> news:3B4FDE7F-6AB0-490C-837A-80FAEE7928AC@microsoft.com...
> > Hi. I develop an ASP.NET web service that calls COM Interop function which
> > do
> > some work by MAPI (change properties of some mails in a given users
> > mailbox)
> > . The problem is when I put my web service under IIS the exception is
> > thrown
> > from Mapi  it can't create profile i didn't try but co-worker says that it
> > doesn't call correctly even MapiInitilize(). I try to enable anonymous
> > access
> > and change the anonymous user to Admin but it doesn't help. All work fine
> > when i use VS2005 integrated Web Server or call Web Service by giving
> > empty
> > credential like this
> >
> > System.Net.CredentialCache cache = new System.Net.CredentialCache();
> > cache.Add(new Uri(url), "NTLM", new NetworkCredential());
> > service.Credentials = cache;
> >
> > Note that my Web Service function is calling before i use credential only
> > com(mapi) is throwing exceptions.
> > Isn't IIS anonymous user has same permissions as empty  NetworkCredential
> > because i am logged in from the same user? by the way i can't leave
> > credentials in the client because i should call this service from Mac
> > client.
> > please help to understand what is the problem. Thanks a lot.
> >
>
>

Sorry, but I didn't use MAPI in .NET. My Web service call ATL COM dll (was
write in C++) and this ATL COM dll WORKING WITH MAPI!!! Web service call ATL
COM dll normaly but I think DLL canot load MAPI32.dll for initialize.... All
problem only in it!!! What can I do?
Author
23 Oct 2007 11:22 AM
SvenC
Hi arsenmkrt,

Show quote
"arsenmkrt" <arsenm***@discussions.microsoft.com> wrote in message
news:3B4FDE7F-6AB0-490C-837A-80FAEE7928AC@microsoft.com...
> Hi. I develop an ASP.NET web service that calls COM Interop function which
> do
> some work by MAPI (change properties of some mails in a given users
> mailbox)
> . The problem is when I put my web service under IIS the exception is
> thrown
> from Mapi  it can't create profile i didn't try but co-worker says that it
> doesn't call correctly even MapiInitilize(). I try to enable anonymous
> access
> and change the anonymous user to Admin but it doesn't help. All work fine
> when i use VS2005 integrated Web Server or call Web Service by giving
> empty
> credential like this

My guess is that the profile cannot be created because in a service process
MAPI profiles are written to mmp files, by default in the windows directory
and I assume that the account used to host the wep service does not have
enough rights to create, change and delete files in that folder.

Please use a tool like FileMon or ProcessMonitor to check for access denied
errors from your web service. If you use IIS6 you need to watch the
w3wp.exe, IIS5.x uses dllhost.exe.

> System.Net.CredentialCache cache = new System.Net.CredentialCache();
> cache.Add(new Uri(url), "NTLM", new NetworkCredential());
> service.Credentials = cache;
>
> Note that my Web Service function is calling before i use credential only
> com(mapi) is throwing exceptions.
> Isn't IIS anonymous user has same permissions as empty  NetworkCredential
> because i am logged in from the same user? by the way i can't leave
> credentials in the client because i should call this service from Mac
> client.
> please help to understand what is the problem. Thanks a lot.

I do not think that the above network credentials have any meaning to MAPI
calls. What uri do you use? This might work for http(s) where you can add
those credentials to your http(s) client code. BTW what type is the service
variable? You seem to think that the service object's Credentials property
does have influence on the authentication of your MAPI calls.

The easiest would be to run the wep service in a domain account which can
access the mailbox you want to access through your web service. Otherwise
you would at least need to create a logon session (LogonUser) and
impersonate that logon in the thread you are using to do MAPI calls. But
IIRC there are some posts around that do advise to not use impersonation
with MAPI...

--
SvenC
Author
24 Oct 2007 5:10 PM
Dan Mitchell
"SvenC" <svenc@community.nospam> wrote in
news:67061F74-8CC4-4A6F-B255-92A0F35287FC@microsoft.com:
> But IIRC there are some posts around that do advise to
> not use impersonation with MAPI...

This is the official word on that:

http://blogs.msdn.com/stephen_griffin/archive/2005/04/13/mapi-and-
impersonation.aspx

-- dan

AddThis Social Bookmark Button