【问题标题】:WCF Service Won't Run on HTTPSWCF 服务不会在 HTTPS 上运行
【发布时间】:2019-01-14 03:34:45
【问题描述】:

我正在运行 IIS 7.5,并且我的 asp.net mvc 网站有一个 SSL 证书。我的服务是对我的网站的免费服务,因此我使用https://www.example.com 访问该网站,并通过https://www.example.com/MyService/Service1.svc 访问我的服务。

我有适用于 HTTP 的代码,但我一直在尝试将其迁移到 HTTPS 以及我在网络上找到的任何示例:Microsoft、Stackoverflow、Youtube 等。它们都以相同的方式执行此操作,但对于某些原因我无法让我的代码运行。谁能帮帮我。

使用“添加服务引用”时的 Visual Studio 错误消息: “下载‘https://www.example.com/MyService/Service1.svc?wsdl/$元数据’时出错。 请求被中止:无法创建 SSL/TLS 安全通道。 元数据包含无法解析的引用:“https://www.example.com/MyService/Service1.svc?wsdl”。 无法为具有“www.example.com”权限的 SSL/TLS 建立安全通道。 请求被中止:无法创建 SSL/TLS 安全通道。 如果在当前解决方案中定义了服务,请尝试构建解决方案并再次添加服务引用。"

在我的服务器上,如果我进入 IIS 管理器并单击我的服务并单击在 *.443(https) 上浏览 www.example.com,我会得到一个目录列表,这是我在 Web 中打开的项目之一.config.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
  </configSections>
  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
    <!--Email Information-->

  </appSettings>
  <!--
    For a description of web.config changes see http://go.microsoft.com/fwlink/?LinkId=235367.

    The following attributes can be set on the <httpRuntime> tag.
      <system.Web>
        <httpRuntime targetFramework="4.5" />
      </system.Web>
  -->
  <system.web>
    <customErrors mode="Off"/>
    <compilation debug="true" targetFramework="4.7" />
    <httpRuntime targetFramework="4.7" />
  </system.web>
  <system.serviceModel>

    <bindings>
      <wsHttpBinding>
        <binding name="secureHttpBinding">  
            <security mode="Transport">  
                <transport clientCredentialType="None"/>  
            </security>  
        </binding>  
      </wsHttpBinding>
    </bindings>
    <services>
      <service name="MyService.MyServiceOperations"  behaviorConfiguration="MyServiceBehavior">
        <host>
            <baseAddresses>
                <add baseAddress="https://www.example.com"/>
            </baseAddresses>
        </host>
        <endpoint address="basic1" binding="wsHttpBinding" bindingConfiguration="secureHttpBinding" contract="MyService.IUserOperations" />
        <endpoint address="basic1" binding="wsHttpBinding" bindingConfiguration="secureHttpBinding" contract="MyService.IPaymentOperations" />
        <endpoint address="basic1" binding="wsHttpBinding" bindingConfiguration="secureHttpBinding" contract="MyService.ILocationOperations" />
        <endpoint address="basic1" binding="wsHttpBinding" bindingConfiguration="secureHttpBinding" contract="MyService.IInfoOperations" />
        <endpoint address="basic1" binding="wsHttpBinding" bindingConfiguration="secureHttpBinding" contract="MyService.IServiceLocationOperations" />
        <endpoint address="basic1" binding="wsHttpBinding" bindingConfiguration="secureHttpBinding" contract="MyService.IHelperOperations" />
        <endpoint address="basic1" binding="wsHttpBinding" bindingConfiguration="secureHttpBinding" contract="MyService.IReporting" />
        <endpoint address="basic1" binding="wsHttpBinding" bindingConfiguration="secureHttpBinding" contract="MyService.ISubItems" />
        <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="MyServiceBehavior">
          <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="jsonEndPoints">
          <webHttp />
        </behavior>
      </endpointBehaviors>
    </behaviors>

    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
    <!--
        To browse web app root directory during debugging, set the value below to true.
        Set to false before deployment to avoid disclosing web app folder information.
      -->
    <directoryBrowse enabled="true" />
  </system.webServer>
  <connectionStrings>
    <!--DB Connection Strings Have been Removed-->
  </connectionStrings>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v13.0" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
     <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.EntityFramework, Version=8.0.13.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"></provider>
    </providers>
  </entityFramework>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="MySql.Data" publicKeyToken="c5687fc88969c44d" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-8.0.13.0" newVersion="8.0.13.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Google.Protobuf" publicKeyToken="a7d26565bac4d604" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.6.1.0" newVersion="3.6.1.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.EntityFrameworkCore" publicKeyToken="adb9793829ddae60" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.1.4.0" newVersion="2.1.4.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Interactive.Async" publicKeyToken="94bc3704cddfc263" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.2.0.0" newVersion="3.2.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Remotion.Linq" publicKeyToken="fee00910d6e5f53b" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.2.0.0" newVersion="2.2.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Extensions.Logging.Abstractions" publicKeyToken="adb9793829ddae60" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.1.1.0" newVersion="2.1.1.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Extensions.DependencyInjection.Abstractions" publicKeyToken="adb9793829ddae60" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.1.1.0" newVersion="2.1.1.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Diagnostics.DiagnosticSource" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.3.1" newVersion="4.0.3.1" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Extensions.DependencyInjection" publicKeyToken="adb9793829ddae60" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.1.1.0" newVersion="2.1.1.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.ComponentModel.Annotations" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.2.1.0" newVersion="4.2.1.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Extensions.Caching.Abstractions" publicKeyToken="adb9793829ddae60" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.1.2.0" newVersion="2.1.2.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Extensions.Caching.Memory" publicKeyToken="adb9793829ddae60" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.1.2.0" newVersion="2.1.2.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.4.1" newVersion="4.0.4.1" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Extensions.Primitives" publicKeyToken="adb9793829ddae60" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.1.6.0" newVersion="2.1.6.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Numerics.Vectors" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.1.4.0" newVersion="4.1.4.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-5.2.7.0" newVersion="5.2.7.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

-----使用唯一能找到的错误代码进行更新-----

事件代码:3005 事件消息:发生未处理的异常。 活动时间:1/13/2019 10:56:55 PM 活动时间(UTC):1/14/2019 5:56:55 AM 事件 ID:ccf077ec0a414d6bb71d178ba496cec1 事件顺序:2 事件发生:1 事件详情代码:0

申请信息: 应用域:/LM/W3SVC/2/ROOT-17-131919190153815312 信任级别:完全 应用程序虚拟路径:/ 应用程序路径:C:\inetpub\wwwroot{Path} 机器名称:WEB

工艺信息: 进程 ID:3848 进程名称:w3wp.exe 账号名:IIS APPPOOL\ASP.NET v4.0

异常信息: 异常类型:HttpException 异常消息:提供的 URI 方案“https”无效;预期的“http”。 参数名称:via 在 System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext 上下文,HttpApplication 应用程序) 在 System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext,HttpContext 上下文,MethodInfo[] 处理程序) 在 System.Web.HttpApplication.InitSpecial(HttpApplicationState 状态,MethodInfo[] 处理程序,IntPtr appContext,HttpContext 上下文) 在 System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext,HttpContext 上下文) 在 System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext)

提供的 URI 方案“https”无效;预期的“http”。 参数名称:via 在 System.ServiceModel.Channels.TransportChannelFactory1.ValidateScheme(Uri via) at System.ServiceModel.Channels.HttpChannelFactory1.ValidateCreateChannelParameters(EndpointAddress remoteAddress, Uri via) 在 System.ServiceModel.Channels.HttpChannelFactory1.OnCreateChannelCore(EndpointAddress remoteAddress, Uri via) at System.ServiceModel.Channels.ChannelFactoryBase1.InternalCreateChannel(EndpointAddress 地址,Uri via) 在 System.ServiceModel.Channels.ServiceChannelFactory.ServiceChannelFactoryOverRequest.CreateInnerChannelBinder(端点地址到,Uri 通过) 在 System.ServiceModel.Channels.ServiceChannelFactory.CreateServiceChannel(EndpointAddress 地址,Uri via) 在 System.ServiceModel.Channels.ServiceChannelFactory.CreateChannel(类型 channelType,EndpointAddress 地址,Uri via) 在 System.ServiceModel.ChannelFactory1.CreateChannel(EndpointAddress address, Uri via) at System.ServiceModel.ClientBase1.CreateChannel() 在 System.ServiceModel.ClientBase1.CreateChannelInternal() at System.ServiceModel.ClientBase1.get_Channel() 在 C:\Users\User\Desktop{Path}\Reference.cs:line 6107 中的 TruckIt.TruckItWebOps.LocationOperationsClient.GetStates(Int32 CountryId) 在 C:\Users\User\Desktop{path}\Global.asax.cs:line 41 中的 MyService.MvcApplication.Application_Start() 处

请求信息: 请求网址:https://www.example.com:443/ 请求路径:/ 用户主机地址:192.168.1.1 用户:
是否经过身份验证:假 身份验证类型:
线程账户名:IIS APPPOOL\ASP.NET v4.0

线程信息: 线程 ID:43 线程账户名:IIS APPPOOL\ASP.NET v4.0 是否冒充:假 堆栈跟踪:在 System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) 在 System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext,HttpContext 上下文,MethodInfo[] 处理程序) 在 System.Web.HttpApplication.InitSpecial(HttpApplicationState 状态,MethodInfo[] 处理程序,IntPtr appContext,HttpContext 上下文) 在 System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext,HttpContext 上下文) 在 System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext)

自定义事件详情:

【问题讨论】:

  • 尝试建立与服务的 HTTPS 连接时收到的错误消息是什么?您是否尝试过启用message logging
  • 没有错误。我可以转到不在服务器上的浏览器并输入服务的 URL,它会弹出 WCF 服务的所有详细信息。它只是不想在 Visual Studio 中连接。
  • 另外,我还没有尝试过消息记录。接下来我会尝试的。感谢您的提示
  • 我添加了我能找到的唯一错误代码。
  • 您的网站似乎无法提供安全连接,也许您可​​以参考链接了解如何配置您的网站以在 wcf https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/how-to-configure-an-iis-hosted-wcf-service-with-ssl 中启用 https

标签: wcf ssl iis


【解决方案1】:

感谢所有给予我理智回应的人。对于那些只是将您引导到另一个页面的愚蠢的人,祝您生活愉快!生活中到处都是平庸的人,我向你保证他们不会走得太远。

至于答案: 所以我的服务会通过一个网络浏览器做出响应,所有的浏览器。所以我知道这不是 web.config 问题。所以我回去调查了一个最初的想法,我遇到了 TLS 和 SSL 问题。

  1. 访问此网站 https://www.ssllabs.com/ssltest/analyze.html?d=casnet.casusa.com&latest

  2. 该网站会告诉您您可能遇到的问题。在我的情况下,我在我的服务器上运行非常旧版本的 TLS 和 SSL。

  3. 我使用以下方法更新了我的 SSL: https://social.technet.microsoft.com/Forums/office/en-US/02241093-187d-41e4-a0fe-1cd19331a9a2/how-to-enable-ssl-v3-on-windows-2008?forum=winserversecurity

  4. 我使用以下方法更新了我的 TLS 1.1 和 1.2: https://tecadmin.net/enable-tls-on-windows-server-and-iis/

  5. 然后我不得不在我的个人计算机上的注册表中更新上述 SSL 和 TLS,而不是插入“服务器”密钥,我最终安装了“客户端”密钥。

更新这些安全协议后,我能够通过截至 2019 年 1 月 14 日的最新版本 Visual Studio 2017 进行连接。再次,我非常感谢那些试图投入工作并给我答案的人。

【讨论】:

    猜你喜欢
    • 2017-05-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-07
    • 2012-01-10
    • 1970-01-01
    • 2019-03-31
    相关资源
    最近更新 更多