【问题标题】:WCF Service Reference Can't be updated over HTTPS无法通过 HTTPS 更新 WCF 服务参考
【发布时间】:2016-01-10 18:19:33
【问题描述】:

我有一些 WCF 服务(由 WinForms 应用程序使用)现在在 IIS 下运行一段时间没有问题。我正打算重新审视它们并添加一些新功能,但现在我遇到了一个问题,当我尝试在 Visual Studio 中更新服务引用时,这个问题首先变得明显。

右键单击现有的服务引用,然后在 Visual Studio 中更新服务引用会引发错误:

下载“https://www.test.com/WCF/MyService.svc”时出错。请求失败,HTTP 状态为 400:错误请求。元数据包含无法解析的引用:(等...)

如果我在网络浏览器中打开 https://www.test.com/WCF/MyService.svchttps://www.test.com/WCF/MyService.svc?wsdl,我也会收到 400 Bad Request。 但是,如果我通过 http(不是 https)访问这些 URL 中的任何一个,那么我会得到服务屏幕和 wsdl。然后我尝试在VS中请求服务更新时使用http,它可以工作,但是这个服务应该只使用HTTPS!

这是我的服务器端web.config

<system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="false" 
            multipleSiteBindingsEnabled="false" 
            minFreeMemoryPercentageToActivateService="0"/>
    <bindings>
        <wsHttpBinding>
            <binding name="wsHttpBindingConfig" 
                 receiveTimeout="00:05:00" sendTimeout="00:01:00" 
                 maxReceivedMessageSize="5000000">
                <security mode="TransportWithMessageCredential">
                    <transport clientCredentialType="None"/>
                    <message clientCredentialType="UserName"/>
                </security>
            </binding>
        </wsHttpBinding>
    </bindings>
    <services>
        <service name="MyService"
                 behaviorConfiguration="ServiceBehavior" >
            <endpoint name="MyServiceEndpoint" 
                address="https://www.test.com/WCF/MyService.svc" 
                binding="wsHttpBinding" 
                bindingConfiguration="wsHttpBindingConfig" 
                contract="IMyService"/>
        </service>
    </services>
    <behaviors>
        <serviceBehaviors>
            <behavior name="ServiceBehavior">
                <serviceMetadata httpGetEnabled="true"/>
                <serviceDebug includeExceptionDetailInFaults="true"/>
                <serviceCredentials>
                    <userNameAuthentication 
                         userNamePasswordValidationMode="MembershipProvider" 
                         membershipProviderName="AspNetSqlMembershipProvider"/>
                </serviceCredentials>
                <serviceAuthorization 
                     principalPermissionMode="UseAspNetRoles" 
                     roleProviderName="AspNetSqlRoleProvider"/>
            </behavior>
            <behavior name="">
                <serviceMetadata httpGetEnabled="true"/>
                <serviceDebug includeExceptionDetailInFaults="false"/>
            </behavior>
        </serviceBehaviors>
    </behaviors>
    <!-- enables WCF logging -->
    <diagnostics wmiProviderEnabled="false" performanceCounters="Off">
        <messageLogging logEntireMessage="true" 
              logMalformedMessages="true" logMessagesAtServiceLevel="true" 
              logMessagesAtTransportLevel="true" maxMessagesToLog="200" 
              maxSizeOfMessageToLog="50000"/>
    </diagnostics>
</system.serviceModel>

一些可能有帮助的背景信息(?):

  1. 刚刚在我的开发机器上升级到 Win10 和 VS2015。尝试在 VS2010 或 VS2015 中更新服务参考会得到相同的结果。

  2. 刚刚意识到我的网络托管公司没有像我付钱给他们那样对服务器应用更新。刚刚对我值得信赖的旧 Win2008 服务器进行了 4 年(!)的 Windows 更新。

  3. Chrome 抱怨我的服务器证书有效但已过时(使用 SHA1),其他浏览器不会抱怨。我正在准备一份 SHA2 证书,但不知道这会有什么不同。

最后,Web 服务现在仍然可以通过 HTTPS 以原始容量运行。但是任何通过 HTTPS 更新引用的尝试都会失败,并出现 400 Bad Request。

两天的 google/stackoverflow 搜索,我什么也想不出来。有人有提示或线索或尝试什么吗?

【问题讨论】:

  • 你已经定义了&lt;serviceMetadata httpGetEnabled="true"/&gt; --> 你可以通过http:// 获取服务元数据——而不是https。尝试添加 https 支持:&lt;serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/&gt; - 这有什么帮助吗?
  • @mark_s:使用 httpGetEnabled="true" 和/或 httpsGetEnabled="true" 在浏览器或 VS 中的差异为零。 ~好像应该~那是什么意思?
  • 我还要提一下,自从上次运行良好以来,我对 web.config 进行了零更改。在我的 VS 客户端项目中,服务引用地址设置为 https(这也是我之前更新它们的方式)。
  • 如果我删除httpGetEnabled="true",那么它会给我一个“此服务的元数据发布当前已禁用”。通过 HTTP 浏览服务时的消息。但是,通过 HTTPS 浏览时,添加 httpsGetEnabled="true" 仍然会给我一个 HTTP 400 错误请求。

标签: .net visual-studio web-services wcf https


【解决方案1】:

我不知道发生了什么,但我以前可以通过 HTTPS 更新引用,现在我不能。我想我很担心,因为我认为这会影响我的 app.config 中端点的“自动配置”。但是,通过 HTTP 更新服务引用似乎对我的 app.config 设置没有影响(通过 HTTPS 访问服务)。

换句话说,没有任何问题。我刚刚通过HTTP更新,我的WinForms应用仍然可以通过HTTPS调用该服务。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-01
    • 2013-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-11
    相关资源
    最近更新 更多