views:

129

answers:

2

Problem

System.ServiceModel.Security.SecurityAccessDeniedException : Access is denied.

Relevant Stack lines (reduced)

Server stack trace: 
at System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(Message reply, MessageFault fault, String action, MessageVersion version, FaultConverter faultConverter)

Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)

Environment
Developer Machine (host): Windows Vista, Visual Studio 2008, nUnit
Test Machine (guest): Windows 2003, IIS, Windows 2003 Firewall (disabled)
Virtual Machine: Virtual PC
Network: Microsoft Loopback Adapter

Description
The Windows 2003 hosts a WCF service inventory, services within are well tested.
When an application consumer runs inside windows 2003 - everything works fine.
When an application consumer runs from Windows Vista (under this virtual network) - security problems appears. So it was needed to adjust de service and include a certificate. Documentation was followed but the access still denied.

Purpose
No sophisticated security arrangements is needed - its simply a laptop and virtual machine. I tried to replicate this official scenario: http://msdn.microsoft.com/en-us/library/ms733938.aspx
I want make calls to services hosted on windows 2003 from my application under Windows Vista OS using the Unit Test application (nunit). The deployed services on windows 2003 is a well tested ones.

WHAT WORKS
Any service using (or past .asmx webservices) works properly.

Suspicion
I believe it has to be with this dammed Windows Vista. The Windows 2003 event log has successful auditing entries.

SERVICE SETTINGS

The consumer - nunit application running on Windows Vista:

<system.serviceModel>
<client>
  <endpoint address="http://soa.homolog.com/RemoteService/RemoteService.svc"
      binding="wsHttpBinding"
      behaviorConfiguration="InternetEndpointBehavior" 
      bindingConfiguration="AnonymousBindingConfiguration"
      contract="RemoteService.IRemoteService" 
      name="WSHttpBinding_IEmpresaService">
    <identity>
      <dns value="homologCertificate"  />
    </identity>
  </endpoint>
</client>
<bindings>
  <wsHttpBinding>
    <binding name="AnonymousBindingConfiguration">
      <security mode="Message">
        <message clientCredentialType="None" />            
      </security>
    </binding>
 </bindings>
 <behaviors>
 <endpointBehaviors>
    <behavior name="InternetEndpointBehavior">
      <clientCredentials>
        <serviceCertificate>
          <authentication certificateValidationMode="None" />
        </serviceCertificate>
      </clientCredentials>
    </behavior>
  </endpointBehaviors>
 </behaviors>
</system.serviceModel>

The service, hosted on IIS/Windows 2003:

<system.serviceModel>
<serviceHostingEnvironment>
  <baseAddressPrefixFilters>
    <add prefix="http://soa.homolog.com" />
  </baseAddressPrefixFilters>
</serviceHostingEnvironment>
<bindings>

  <wsHttpBinding>
    <binding name="BindingNoSecurity">          
      <security mode="Message">
        <message clientCredentialType="None"/>
      </security>
    </binding>
  </wsHttpBinding>
</bindings>
<behaviors>
  <serviceBehaviors>
    <behavior name="CompanyCoreBehavior">

      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug 
              includeExceptionDetailInFaults="true" />
      <serviceThrottling 
              maxConcurrentCalls="500" 
              maxConcurrentInstances="500" 
              maxConcurrentSessions="500" />
      <serviceTimeouts 
              transactionTimeout="00:10:00" />

      <serviceCredentials>
        <serviceCertificate
                    findValue="homologCertificate"
                    storeLocation="LocalMachine"
                    x509FindType="FindBySubjectName"
                    storeName="My"/>
      </serviceCredentials>
    </behavior>
  </serviceBehaviors>
</behaviors>

A: 

This is a System.ServiceModel.Security exception so it is probably not a firewall or IIS problem.

Try removing the following code from the client:

  <clientCredentials> 
    <serviceCertificate> 
      <authentication certificateValidationMode="None" /> 
    </serviceCertificate> 
  </clientCredentials> 

And the following code from the server:

  <serviceCredentials>  
    <serviceCertificate  
                findValue="homologCertificate"  
                storeLocation="LocalMachine"  
                x509FindType="FindBySubjectName"  
                storeName="My"/>  
  </serviceCredentials>  
Shiraz Bhaiji
Sorry bro, I started exactly the way you're proposing. And I believe the WCF staff is not so interpretable because it seens I have to in windows networking with a proper security setting and policy, not just a virtual machine.
Eduardo Xavier
A: 

Start by enabling WCF tracing on the server. The trace log may contain a meaningful error message. Enable message logging and see if there any obvious differences between the messages that are accepted and those that are not. Although, honestly, I don't see how this can happen in your case.

Dmitry Ornatsky
Understood. Although I had stared this scenario from a very simple communication. Tried consumer and service in the same machine thereafter the service was deployed in this remote machine (on the virtual server). So, I started to see Microsoft sample scenarios. None of that worked. I'll try your approach little more even considering that WCF tracing is kind of find "needle in a haystack". Interestingly to say again that .asmx services works proudly.
Eduardo Xavier