DllImport and WebMethod and STAThread

Posted: 12-01-2003, 06:53 PM
I'm trying to use a 3rd party DLL, which I have no control over, in my
WebService (written in C#). However, every time my WebService tries to
call one of the dllimport-ed methods it simply never returns from the
call. I know the DLL is there and it works well in many console and
windows applications I have done.

I have been able to create a console application that fails in the
same way, at least I think it does!?!? It fails if I take the
[STAThread] from the main method. Then I get a message dialog saying
"The operating system cannot load the DLL module. Please check that
the DLL module exists, and that any other DLL modules that it will use
also exist." The DLL is there and it works if I put the [STAThread]
back on the main method.

How do I make part of my WebService use the STAThread model instead of
the multi-threaded model? I realize I don't want to do this all over,
just partially?!?!

I have seen some discussions about using dllimport and WebServices
together but nothing that can help me. All your help is highly
appreciated.

Looking forward to hearing from you.

Thanks.
Reply With Quote

Responses to "DllImport and WebMethod and STAThread"

Alfred B. Thordarson
Guest
Posts: n/a
 
Re: DllImport and WebMethod and STAThread
Posted: 12-02-2003, 05:01 PM
I was able to call the dllimport-ed methods, in a webservice, by
creating a new thread, changing it's ApartmentState into STA, and then
have it run my dllimport-ed methods. This is a major hassle if I have
many different methods with different parameters. Is there really no
other way to do this?

--snippet:
Thread staThread=new Thread(new
ThreadStart(newHandler.STAAppendRecordsetXml));
staThread.ApartmentState=ApartmentState.STA;
staThread.Start();

There must be a better way?

-Alfred

athordarson@landsteinar.je (Alfred B. Thordarson) wrote in message news:<79fc7025.0312011153.63456edd@posting.google. com>...
> I'm trying to use a 3rd party DLL, which I have no control over, in my
> WebService (written in C#). However, every time my WebService tries to
> call one of the dllimport-ed methods it simply never returns from the
> call. I know the DLL is there and it works well in many console and
> windows applications I have done.
>
> I have been able to create a console application that fails in the
> same way, at least I think it does!?!? It fails if I take the
> [STAThread] from the main method. Then I get a message dialog saying
> "The operating system cannot load the DLL module. Please check that
> the DLL module exists, and that any other DLL modules that it will use
> also exist." The DLL is there and it works if I put the [STAThread]
> back on the main method.
>
> How do I make part of my WebService use the STAThread model instead of
> the multi-threaded model? I realize I don't want to do this all over,
> just partially?!?!
>
> I have seen some discussions about using dllimport and WebServices
> together but nothing that can help me. All your help is highly
> appreciated.
>
> Looking forward to hearing from you.
>
> Thanks.
Reply With Quote
 
LinkBack Thread Tools Search this Thread Display Modes
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
web service delete row WebMethod ? Michael Coughlin ASP.NET Web Services 0 11-12-2003 12:41 AM
Webmethod OnEnd Sriram ASP.NET Web Services 1 10-16-2003 01:37 PM
cant add another webmethod :( Lasse Edsvik ASP.NET Web Services 2 09-22-2003 07:51 PM
How to use own classes as WebMethod-Parameters? Daniel Barisch ASP.NET Web Services 1 09-01-2003 12:53 PM
DataTable parameter of a WebMethod? Emre Aydinceren ASP.NET Web Services 0 07-08-2003 09:19 PM