trouble with wcf on iis, access to dll denied.


  • Hallo!

    I've got a trouble with wcf.

    When I deploy my solution to iis, it works fine some time. Then something goes wrong and all calls to the service fail with exception like "cannot load assembly ... access denied."  This assembly is in bin directory in the root of the service.
    iis has version six.  Windows 2003 R2. application pool runs under AD-account with local Admin rights. Anonymous logon disabled. Integrated security turned on at site configuration. transport security via ssl is turned on.

    Also custom behaviour is used. this behaviour just impersonates user at contract access level. (I've tried to use standard impersonation scheme, but got these exceptions again)


    <?xml version="1.0" encoding="utf-8" ?>
        <compilation debug="true" />
        <customErrors mode="Off"/>
            <add name="BehaviorExtension" type="Extensions.BehaviorExtensionElement, Extensions, Version=, Culture=neutral, PublicKeyToken=null"/>
            <binding name = "wsHttpBinding2">
              <security mode="Transport">
                <transport clientCredentialType="Windows" proxyCredentialType="None" realm="" />
          <service name="Services.MyService" behaviorConfiguration="MainBehavior">
                <add baseAddress=""   />
            <endpoint address="" binding="wsHttpBinding" bindingConfiguration="wsHttpBinding2" contract="Services.IMyService"  behaviorConfiguration="MainEndPointBehavior">
                <servicePrincipalName value="HTTPS/" />
            <behavior name="MainBehavior">
              <serviceMetadata httpGetEnabled="true" />
              <serviceDebug includeExceptionDetailInFaults="true" />
              <serviceThrottling maxConcurrentCalls="160" maxConcurrentSessions="100"
                maxConcurrentInstances="260" />
              <serviceAuthorization principalPermissionMode="UseWindowsGroups"/>
            <behavior name="MainEndPointBehavior">
              <BehaviorExtension />
          <add name="Data.Properties.Settings.ConnectionString"
              connectionString="Data;Initial Catalog=MyDB;Integrated Security=True;Connect Timeout=10"
              providerName="System.Data.SqlClient" />

    impersonation code:

        public class MyMessageInspector : IDispatchMessageInspector
            #region IDispatchMessageInspector Members
            public object AfterReceiveRequest(ref System.ServiceModel.Channels.Message request, IClientChannel channel, InstanceContext instanceContext)
                if (ServiceSecurityContext.Current != null)
                    if (!ServiceSecurityContext.Current.IsAnonymous)
                        WindowsImpersonationContext ctx = ServiceSecurityContext.Current.WindowsIdentity.Impersonate();
                        return ctx;
                        throw new Exception(string.Format("WCF: Anonymous logon is not supported by {0} operation of {1} endpoint", request.Headers.Action, request.Headers.To));
                else return null;
            public void BeforeSendReply(ref System.ServiceModel.Channels.Message reply, object correlationState)
                if (correlationState != null)
                    WindowsImpersonationContext ctx = correlationState as WindowsImpersonationContext;

     Help, please. I've lost 4 days with it, and have no idea about resulution.

    Thank you.

    Tuesday, September 15, 2009 11:12 AM

All replies