calling unmanged c-dll from webservice

  • Thread starter Nicki Carstensen
  • Start date
N

Nicki Carstensen

hi all

I have a class that hooks up to a matlab engine dll that looks something
like this:
class MatlabConn
{
IntPtr engine;

DllImport("libeng.dll")]
static extern IntPtr engOpen(string startcmd);

MatlabConn()
{
engine = engOpen(null);
if(engine == IntPtr.Zero)
throw new NullReferenceException("engine creation failed");
}
....
}
When the code is used in a winform app it works perfectly, but when i
try to use it in a webservice, the call til engOpen returns null and
thus the exception is thrown. engOpen is supposed to start a Matlab
provcess and as far as I understand it does so via COM but the
libeng.dll is not a COM-dll itself. I've tried to switch impersonation
context like this:

[WebMethod]
void DoStuff()
{
IntPtr hToken;
LogonUser("Administrator", ".", "pass", 3, 0, out hToken);
WindowsIdentity id = new WindowsIdentity(hToken);
WindowsImpersonationContext wic = id.Impersonate();
MatlabConn matlab = new MatlabConn();
wic.Undo();
....
}
Then it works fine, but I'm not very fond of having to use the local
administrator account directly in code.
Is there a way to use a non-admin user instead og the admin, or is it
possible to allow the aspnet/network serivce account to launch the
matlab process?

Thanks in advance, and sorry for the novel :)

Nicki Carstensen
remove the car in my email
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top