ASP.NET application/web service not working on Windows Vista/IIS 7: access right problem

asp.netiis-7service

I have a .NET 3.5 based web service running at http://localhost/serivce.svc/. Then I have an ASP.NET application running at http://localhost/myApp. In Application_Load my application reads some XML configuration from the web service. That works fine on my machine, but:

  • On Windows Vista with IIS 7 the request to the web services fails.
  • The web service can be accessed via the browser without any problem.
  • I configured the app pool of my application to run as admin. I added the admin to the IIS_USRS group, but it still cannot access the web service. impersonate=true/false seems not to make a difference.

Best Answer

First off, take admin out of the IIS_WPG group before you forget, and configure your app pool back to normal.

Now, turn on WCF logging on the service by putting the following in your web.config file -

<system.diagnostics>
    <sources>
        <source name="System.ServiceModel.MessageLogging" switchValue="Warning, ActivityTracing">
            <listeners>
                <add type="System.Diagnostics.DefaultTraceListener" name="Default">
                    <filter type="" />
                </add>
                <add name="ServiceModelMessageLoggingListener">
                    <filter type="" />
                </add>
            </listeners>
        </source>
    </sources>
    <sharedListeners>
        <add initializeData="c:\logs\web_messages.svclog"*
            type="System.Diagnostics.XmlWriterTraceListener, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
            name="ServiceModelMessageLoggingListener" traceOutputOptions="Timestamp">
            <filter type="" />
        </add>
    </sharedListeners>
</system.diagnostics>


<system.serviceModel>
...
   <diagnostics>
     <messageLogging logMalformedMessages="true" *logMessagesAtServiceLevel="true"*
       logMessagesAtTransportLevel="true" />
   </diagnostics>
...
</system.ServiceModel>

Create the c:\logs directory and make sure the application pool identity user has full control on that directory. Now test your app.

If no log files are being created then there's a problem reaching the WCF service. If log files are being created view them in the Service Trace viewer which comes as part of the Windows SDK. You'll see a red message which is the log entry containing the exception thrown inside the service - this should give you a pointer to where your service code is going wrong.

If the problem is inside your app, rather than the service then you should be logging exceptions inside your Application_Load event (you should be logging exceptions anyway) - however if you try with a global exception handler, well, your app is failing on startup and so the global exception handler will never start to run - instead of putting potential failable scenarios in Application_Load I'd move that out to a utility class which provides an access point to the information you need (say myGlobalThingumy.GetStuff()). Make this class a singleton, and then check if you have the stuff already - if you don't, then you make your web service call. It would act much the same as putting it in Application_Load but will enable global error handling to work, and make your debugging easier.