WCF - strange error

I have a dll hosted in IIS with wsHttpBinding . I have this strange error occurred in between.

Ok, everything will be restored again when I reset IIS (iisreset).

I also read this http://msdn.microsoft.com/en-us/library/ee517280.aspx . But I'm not sure if this is related to this. Please guide me if you have more information about this. Thanks.

Server error in application '/ MSBuildCompilation'.

Either the required impersonation level has not been provided, or if the impersonation level is invalid. (Exception from HRESULT: 0x80070542) Description: An unhandled exception occurred during the execution of the current web request. View the stack trace for more information about the error and its occurrence in the code.

Exception Details: System.Runtime.InteropServices.COMException: Either the required impersonation level was not provided or the Invalid impersonation level was provided. (Exception from HRESULT: 0x80070542)

Source Error:

An unhandled exception was thrown during the execution of the current web request. Information about the origin and location of the exception can be identified using the exception stack trace below.

Stack trace:

[COMException (0x80070542): either the required impersonation level was not provided, or the provided impersonation level is invalid. (Exception from HRESULT: 0x80070542)]

[FileLoadException: Unable to load file or assembly 'System.ServiceModel, Version = 4.0.0.0, Culture = neutral, PublicKeyToken = b77a5c561934e089' or one of its dependencies. Either the required impersonation level has not been provided or the Invalid impersonation level has been provided. (Exception from HRESULT: 0x80070542)] System.ServiceModel.Activation.HttpModule.ProcessRequest (Object sender, EventArgs e) +0
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute () +148 System.Web.HttpApplication.ExecuteStep (step IExecutionStep, Logical & completed synchronously) +75

+4
source share
2 answers

It looks like you are trying to run the .NET 4.0 Framework in IIS6, which will be complicated according to this post. I have not tried myself. The exception you get is actually happening because your process unsuccessfully tries to load the System.ServiceModel version 4.0 DLL. Although this message is for ASP.NET, it is applicable to WCF because ASP.NET is the service host process in IIS6. Here is another question on the same lines with some good answers.

+1
source

(The original poster answered, but in the wrong place, moved by me.)

Hi everyone, I finally solved my problem by adding these 2 lines to my client application code:

  WindowsClientCredential wsCred = wsFactory.Credentials.Windows; wsCred.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation; 

These two lines are to force the client to impersonate each time it connects.

+1
source

All Articles