RE: RE: WCF Service Library: “cannot change thread mode after it is set”



Hi Phillip,

From your description, you're encountering some error when consumning a WCF
service object in non-WPF clients(console, windows service ...), correct?

I've viewed your two messages and currently my understanding is that the
problem only occurs when you call that WCF method(or the object) which will
invoke another COM interoped object, is this the case? If so, I also think
the problem should be concentreated on the COM component. Would you please
provide some further description on that method which call the COM
objects(the RCW wrapper?) , are you directly creating the RCW wrapper
object in WCF method?

Normally, for cases that we need to call a component in STA apartment(and
the current thread context is already set as "MTA"), you can consider
creating a separate thread to invoke the COM objects calling. e.g.

============
protected void YourMethodInMTAContext{

..............

Thread thread = new Thread(delegate() {
//the code that will call the STA COM object
});
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
thread.Join();


}
=========================

If there is anything else I missed, please feel free to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================


This posting is provided "AS IS" with no warranties, and confers no rights.



--------------------

From: =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?= <WEBSWAPP@xxxxxxxxxxxxxxxxx>
References: <AAE526BE-8C21-4DF0-BD5B-F0E63926EE4C@xxxxxxxxxxxxx>
Subject: =?Utf-8?Q?RE:_WCF_Service_Library:_=E2=80=9Ccannot?=
=?Utf-8?Q?_change_thread_mode_after_it_is_?=
=?Utf-8?Q?set=E2=80=9D?=
Date: Thu, 4 Oct 2007 14:06:01 -0700

I also tried a fourth endpoint hosted in IIS, it has the same problem as
the
console host.

So to summarize, I have a WCF service library hosted by four different
types
of application: WPF, console, Windows Service and IIS. The four endpoints
work fine from any client application when accessing methods that do not
activate the COM object.

If a client application attempts to access a method that activates the COM
object by connecting to the endpoint that is hosted in WPF it works fine.

The problem is when a client app accesses the methods that activate the
COM
object at the endpoints that are hosted by console, or IIS or Windows
Service
apps.

--
Regards,

Phillip Williams (MCPD Web Developer)
http://mcts-study-practices.com/
http://www.webswapp.com


"Phillip Williams" wrote:

I have a JavaClass component (dll) that I am required to access within a
WCF
Service Library and then expose the data that it returns to other
..NET3.0
apps. The WCF Service Library is written in VB but the host and client
are
written in C#. The Service library works fine (in instantiating the COM
object) if the calling host is a WPF (Windows Application) but it does
not
work if the calling host were a console or a Windows Service.

On the console host, I get a message â??cannot change thread mode after
it is
setâ??echoed on the host console window. If I step using the debugger
through
the service, I find that it catches a
System.Runtime.InteropServices.COMException at the line: myVar = New
myLib.SomeObject

After searching for similar error messages, I understood that the
problem is
related to the threading model of the COM object so I added STAThread on
every method in the service, host and the client applications. But
still the
same problem exists for the console and WinService host.

Any ideas?

--
Regards,

Phillip Williams (MCPD Web Developer)
http://mcts-study-practices.com/
http://www.webswapp.com


.



Relevant Pages

  • RE: WCF Security Issue
    ... ** Is your WCF service designed to use domain ... both wsHttpbinding and netTcpBinding support message ... Then, for your WCF client, you can use the current logon user's credential ... Microsoft MSDN Online Support Lead ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • Re: System.Configuration does not support config files for libraries.
    ... Seems what you want to do is sharing some custom classes/types between the WCF service and client application. ... For WCF there is type sharing support. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: System.Configuration does not support config files for libraries.
    ... a class library) between the WCF service and client application. ... there is type sharing support. ... Microsoft MSDN Online Support Lead ...
    (microsoft.public.dotnet.languages.csharp)
  • RE: folder virtualisation
    ... client GUI application. ... Yes, based on my feedback, it seems that the named pipe object may be ... Microsoft Online Community Support ... where an initial response from the community or a Microsoft Support ...
    (microsoft.public.platformsdk.security)
  • RE: Web App With Signature
    ... use some rich client approach such as ACTIVEX control. ... retrieve protect resource on client(such as file system or certificate ... Microsoft MSDN Online Support Lead ... where an initial response from the community or a Microsoft Support ...
    (microsoft.public.dotnet.framework.aspnet)

Quantcast