【问题标题】:WCF hosted on IIS express ssl enabledWCF 托管在 IIS express ssl 上启用
【发布时间】:2015-05-05 17:46:15
【问题描述】:

我已经苦苦挣扎了一个星期了,我正在尝试在 IIS express 上运行 WCF 服务并从浏览器执行 GET,在 HTTP 中一切正常,但是在我尝试 HTTPS 的那一刻失败

HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

我已经尝试了 stackoverflow 答案中的每个配置文件我也尝试了this 我知道它适用于 IIS,但我不明白为什么它在 IIS express 上不起作用。这是我的配置文件:

<?xml version="1.0"?>
<configuration>


  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5"/>
  </system.web>


  <system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
    <behaviors>
      <endpointBehaviors>

        <behavior name="webHttpEnablingBehaviour">

          <webHttp />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>

        <behavior name="webHttpEnablingBehaviour">
          <serviceMetadata httpGetEnabled="true" />
        </behavior>

      </serviceBehaviors>
    </behaviors>
    <services>
      <service
        name="ElasticSearchAPI.GetElasticService" behaviorConfiguration="webHttpEnablingBehaviour">
        <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />

        <endpoint address=""
          binding="webHttpBinding"
          bindingConfiguration="default"
          contract="ElasticSearchAPI.IGetElasticService"
          behaviorConfiguration="webHttpEnablingBehaviour">
        </endpoint>
        <endpoint address="other"
          binding="basicHttpBinding"
          bindingConfiguration="default"
          contract="ElasticSearchAPI.IGetElasticService">
        </endpoint>
      </service>

    </services>
    <client />
    <bindings>
      <webHttpBinding>
        <binding name="default" ></binding>
      </webHttpBinding>
      <basicHttpBinding>
        <binding name="default" allowCookies="true"></binding>
      </basicHttpBinding>
    </bindings>
  </system.serviceModel>

  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <validation validateIntegratedModeConfiguration="false"/>
    <!--
        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"/>

    <httpProtocol>
      <customHeaders>
        <add name="Access-Control-Allow-Origin" value="*" />
      </customHeaders>
    </httpProtocol>

  </system.webServer>

</configuration>

我确信我错过了一些非常愚蠢的东西,但我真的没有想法,非常感谢你的帮助。

更新

我可以使用 https 访问我的 .svc,但是当我尝试从浏览器获取或从提琴手发帖时,没有任何效果

【问题讨论】:

标签: c# wcf ssl https wcf-binding


【解决方案1】:

使用如下所示的 ServiceBehaviour-

<serviceBehaviors>
    <behavior>
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
</behavior>

这可能会对你有所帮助。

【讨论】:

    【解决方案2】:

    在 WCF 服务配置文件中添加以下内容:

    <binding name="secureHttpBinding">
     <security mode="Transport">
      <transport clientCredentialType="None" />
     </security>
    </binding>
    

    在客户端应用程序配置文件中添加以下内容:

    <httpProtocol>
     <customHeaders>
            <add name="Access-Control-Allow-Origin" value="*" />
     </customHeaders>
    </httpProtocol>
    

    这将允许您使用 HTTPS 协议托管和访问 WCF 服务。

    【讨论】:

    • 谢谢,但正如我在评论中提到的,问题已经解决。仅供参考,使用了Access-Control-Allow-Origin,因此您可以克服 CORS,而不是针对 https 协议,而是针对跨域。
    • 感谢您的信息。如果服务托管在 HTTPS 上并且客户端从 HTTP(您从 HTTP 请求)特别是在 SOA 中为多个客户端请求,那么您需要使用 Access-Control-Allow-Origin。这就是为什么我提到要添加客户端配置文件以防止进一步的错误。
    猜你喜欢
    • 2014-09-09
    • 2016-06-06
    • 2013-10-01
    • 1970-01-01
    • 2011-07-26
    • 2012-07-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多