【问题标题】:Connection reset when contacting a WCF service hosted in IIS 7.5联系 IIS 7.5 中托管的 WCF 服务时连接重置
【发布时间】:2012-02-10 16:27:34
【问题描述】:

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

下面是我的 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 配合使用。打败我,我怎么可能弄清楚问题是什么......

【问题讨论】:

    标签: wcf iis iis-7.5 wif


    【解决方案1】:

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

    【讨论】:

    • 我将我的 web.config 文件与 Windows Identity Training Kit 中的一个文件进行了比较,我没有发现任何明显的差异。只是为了笑,我尝试了您推荐的更改,但我仍然得到相同的行为。不过,谢谢您的建议。
    【解决方案2】:

    我为此向 Microsoft 提出了支持案例。经过大量的日志和跟踪文件的挖掘,我们确定 IIS 中虚拟目录的物理路径不正确。这很奇怪,因为当我将项目添加到我的解决方案时,Visual Studio 代表我创建了虚拟目录。我手动删除并重新创建了虚拟目录,一切都开始工作了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-07-14
      • 2011-07-25
      • 2022-12-13
      • 2012-03-05
      • 2011-05-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多