【问题标题】:WCF gets Access denied when the consumer try invoke a WCF service calls hosted on Virtual Machine当消费者尝试调用托管在虚拟机上的 WCF 服务调用时,WCF 被拒绝访问
【发布时间】:2011-04-15 04:11:39
【问题描述】:

问题

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

相关堆栈行(减少)

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)

环境
开发机器(主机):Windows Vista、Visual Studio 2008、nUnit
测试机(访客):Windows 2003、IIS、Windows 2003 防火墙(禁用)
虚拟机:虚拟 PC
网络:Microsoft 环回适配器

说明
Windows 2003 托管 WCF 服务清单,其中的服务经过良好测试。
当应用程序使用者在 Windows 2003 中运行时 - 一切正常。
当应用程序使用者从 Windows Vista(在此虚拟网络下)运行时 - 出现安全问题。因此需要调整服务并包含证书。遵循了文档,但访问仍然被拒绝。

目的
不需要复杂的安全安排 - 只需一台笔记本电脑和虚拟机。 我试图复制这个官方场景:http://msdn.microsoft.com/en-us/library/ms733938.aspx
我想使用单元测试应用程序 (nunit) 从我在 Windows Vista 操作系统下的应用程序调用托管在 Windows 2003 上的服务。在 windows 2003 上部署的服务是经过良好测试的。

什么有效
任何使用(或过去的 .asmx 网络服务)的服务都可以正常工作。

怀疑
我相信它必须与这个被阻止的 Windows Vista 一起使用。 Windows 2003 事件日志有成功的审核条目。

服务设置

在 Windows Vista 上运行的消费者 - nunit 应用程序:

<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>

托管在 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>

【问题讨论】:

  • 您使用的是哪个虚拟机提供商?虚拟 PC 还是 VMWare?
  • 嗨 Chuck Haines,虚拟 PC..
  • 很好的问题描述!请问您为什么在证书指定 None 时坚持使用消息安全性?
  • 还有“当应用程序使用者在 Windows 2003 中运行时 - 一切正常。当应用程序使用者从 Windows Vista(在此虚拟网络下)运行时 - 出现安全问题。”这是否意味着服务器和客户端都在单独的 VPC 中运行?
  • 我假设您已经关闭了 Windows 2003 机器上的防火墙?

标签: wcf windows-vista iis-6 virtual-machine


【解决方案1】:

这是一个 System.ServiceModel.Security 异常,因此它可能不是防火墙或 IIS 问题。

尝试从客户端删除以下代码:

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

以及来自服务器的以下代码:

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

【讨论】:

  • 对不起兄弟,我完全按照你的提议开始了。而且我相信 WCF 工作人员不是那么容易理解,因为它认为我必须在 Windows 网络中使用适当的安全设置和策略,而不仅仅是虚拟机。
【解决方案2】:

从服务器上的enabling WCF tracing 开始。跟踪日志可能包含有意义的错误消息。启用message logging 并查看接受的消息和不接受的消息之间是否存在明显差异。虽然,老实说,我不明白你的情况是如何发生的。

【讨论】:

  • 明白。虽然我是从一个非常简单的交流中看到这个场景的。在同一台机器上尝试了消费者和服务,之后服务被部署在这个远程机器上(在虚拟服务器上)。因此,我开始查看 Microsoft 示例场景。这些都不起作用。即使考虑到 WCF 跟踪有点像“大海捞针”,我也会尝试您的方法。有趣的是,再次自豪地说 .asmx 服务可以正常工作。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-01-05
  • 2014-12-21
  • 2013-12-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多