联系在IIS 7.5中托管的WCF服务时重置连接

问题描述:

我正在尝试使用WCF安全令牌服务网站模板创建一个虚拟安全令牌服务。当创建网站时,如果我指定一个文件系统URI并在ASP.NET开发Web服务器中托管该站点,那么一切似乎都没有问题。但是,我希望STS使用SSL,并且还希望避免使用由ASP.NET Development Web Server分配的动态端口时出现的跨域问题。因此,我重新创建了相同的网站,但在IIS 7.5中为预配置的Web应用程序指定了HTTPS URI(例如https://localhost/SecurityTokenService/),而不是文件系统URI。现在,所有尝试导航到Service.svc文件都会导致强制连接重置。联系在IIS 7.5中托管的WCF服务时重置连接

下面是我的web.config文件,虽然它在ASP.NET开发Web服务器中托管的事实让我觉得问题出在IIS设置上。我可能会尝试弄清楚发生了什么事情?

<?xml version="1.0" encoding="UTF-8"?> 
    <configuration> 
     <configSections> 
      <section name="microsoft.identityModel" type="Microsoft.IdentityModel.Configuration.MicrosoftIdentityModelSection, Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /> 
     </configSections> 
     <appSettings> 
      <add key="IssuerName" value="ActiveSTS"/> 
      <add key="SigningCertificateName" value="CN=STSTestCert"/> 
      <add key="EncryptingCertificateName" value=""/> 
     </appSettings> 
     <connectionStrings /> 
     <location path="FederationMetadata"> 
      <system.web> 
       <authorization> 
        <allow users="*"/> 
       </authorization> 
      </system.web> 
     </location> 
     <system.web> 
      <compilation debug="true" targetFramework="4.0"> 
       <assemblies> 
        <add assembly="Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> 
       </assemblies> 
      </compilation> 
      <authentication mode="None"/> 
      <pages> 
       <controls> 
        <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> 
       </controls> 
      </pages> 
     </system.web> 
     <system.web.extensions> 
      <scripting> 
       <webServices> 
       </webServices> 
      </scripting> 
     </system.web.extensions> 
     <system.serviceModel> 
      <services> 
       <service name="Microsoft.IdentityModel.Protocols.WSTrust.WSTrustServiceContract" behaviorConfiguration="ServiceBehavior"> 
        <endpoint address="https://localhost/SecurityTokenService/Service.svc/IWSTrust13" binding="ws2007HttpBinding" contract="Microsoft.IdentityModel.Protocols.WSTrust.IWSTrust13SyncContract" bindingConfiguration="ws2007HttpBindingConfiguration"/> 
        <host> 
         <baseAddresses> 
          <add baseAddress="http://localhost/SecurityTokenService/Service.svc" /> 
         </baseAddresses> 
        </host> 
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
       </service> 
      </services> 
     <bindings> 
      <ws2007HttpBinding> 
       <binding name="ws2007HttpBindingConfiguration"> 
        <security mode="TransportWithMessageCredential"> 
         <message establishSecurityContext="false" clientCredentialType="UserName" /> 
        </security> 
       </binding> 
      </ws2007HttpBinding> 
     </bindings> 
     <behaviors> 
      <serviceBehaviors> 
       <behavior name="ServiceBehavior"> 
        <serviceMetadata httpGetEnabled="true" /> 
        <serviceDebug includeExceptionDetailInFaults="false" /> 
       </behavior> 
      </serviceBehaviors> 
     </behaviors> 
    </system.serviceModel> 
    <microsoft.identityModel> 
     <service> 
      <securityTokenHandlers> 
       <remove type="Microsoft.IdentityModel.Tokens.WindowsUserNameSecurityTokenHandler, Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> 
       <add type="CustomUserNamePasswordTokenHandler, App_Code"/> 
      </securityTokenHandlers> 
     </service> 
    </microsoft.identityModel> 
</configuration> 

更新:我可以导航到Web应用程序中的其他文件。只是不是* .svc文件。除了101 statuc代码之外,我没有任何工作要做,所以这很令人沮丧。

更新:进一步的实验表明,问题只存在于STS和托管在IIS中的WCF服务。如果我在IIS中托管常规WCF服务,则没有问题。我下载了各种包含自定义STS的示例项目,并且它们都表现出相同的行为。这使我相信我的IIS的配置存在问题,导致它无法与STS一起玩。打我,我怎么可能找出问题所在......

我与微软就此开了一个支持案例。在深入了解大量日志和跟踪文件后,我们确定IIS中虚拟目录的物理路径不正确。这很奇怪,因为当我将项目添加到我的解决方案时,Visual Studio代表我创建了虚拟目录。我手动删除并重新创建虚拟目录,一切开始工作。

您服务中的基地址配置为HTTP而非HTTPS。另外,如果您使用HTTPS浏览它并期望看到服务定义,我认为您需要httpsGetEnabled而不是httpGetEnabled。这些会成为问题吗?

+0

我将我的web.config文件与Windows Identity Training Kit中的一个进行了比较,我没有看到任何明显的差异。只是为了咧嘴笑,我尝试了你推荐的改变,而且我仍然得到相同的行为。不过谢谢你的建议。 – 2012-02-10 21:46:38