【问题标题】:WCF rest service http to https error 404WCF 休息服务 http 到 https 错误 404
【发布时间】:2017-08-14 08:07:46
【问题描述】:

我正在使用 Visual Studio 2015。我有一个 Xamarin Cross-Platfom 的项目。 我的 WCF 休息服务适用于 http。我尝试使用 HTTPS,但在尝试访问我的资源时收到“未找到 404 错误”。 您将在配置文件下方找到:

web.config

<?xml version="1.0" encoding="utf-8"?>
 <configuration>

 <appSettings>
   <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
 </appSettings>
 <system.web>
   <compilation debug="true" targetFramework="4.5.2" />
   <httpRuntime targetFramework="4.5.2" />
 </system.web>
 <system.serviceModel>
<services>
  <service name="PrototypeBHost.PrototypeB"   behaviorConfiguration="ServiceBehaviour">
    <endpoint address="" binding="webHttpBinding" bindingConfiguration="webHttpTransportSecurity"
    behaviorConfiguration="restfulBehavior"
    contract="PrototypeBHost.IprototypeB" />

<endpoint contract="IMetadataExchange" binding="mexHttpsBinding" address="mex" />     
  </service>
</services>
<bindings>
  <webHttpBinding>
    <binding name="webHttpTransportSecurity">
      <security mode="Transport" />
    </binding>
  </webHttpBinding>
</bindings>
<behaviors>
  <endpointBehaviors>
    <behavior name="restfulBehavior">
      <webHttp/>
    </behavior>
  </endpointBehaviors>
  <serviceBehaviors>
    <behavior name="ServiceBehaviour">
      <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
      <serviceMetadata httpsGetEnabled="true" httpGetEnabled="false"/>
      <!-- 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="false" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<protocolMapping>
    <add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>    
<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>
</configuration>

applicationhost.config

<site name="PrototypeBHost" id="2">
            <application path="/" applicationPool="Clr4IntegratedAppPool">
                <virtualDirectory path="/" physicalPath="c:\Users\Ludovic\Documents\Visual Studio 2015\Projects\PrototypeB\PrototypeBHost" />
            </application>
            <bindings>
            <!--    <binding protocol="http" bindingInformation="*:9612:192.168.1.106" />
                <binding protocol="http" bindingInformation="*:8023:localhost" />-->
                <binding protocol="https" bindingInformation="*:9612:192.168.1.106" />
                <binding protocol="https" bindingInformation="*:8023:localhost" />  
            </bindings>
        </site>

我遵循了一些关于 WCF Rest 的教程,但我对 SSL 证书有点困惑。我需要吗?如何将 ssl 证书附加到 WCF 休息服务?我错过了什么吗?

My_WCF_proprieties

【问题讨论】:

标签: c# rest wcf ssl https


【解决方案1】:

我终于发现问题出在哪里了,IIS Express 的默认证书不起作用并造成了一些麻烦。 首先,我删除了一个证书,我使用 VS2015 的命令提示符

netsh http delete sslcert ipport=0.0.0.0:44300

在那之后 我添加了一个自签名证书

netsh http add sslcert ipport=0.0.0.0:44300 certhash=fb02ea72ab7443604aa8frib298e43l751ce3606 appid={214124cd-d05b-4309-8p76-9caa44b2b74a}

显示所有证书的命令

netsh http show sslcert > output.txt

它有效:)

【讨论】:

    猜你喜欢
    • 2014-08-10
    • 1970-01-01
    • 1970-01-01
    • 2023-03-26
    • 1970-01-01
    • 2015-09-29
    • 1970-01-01
    • 2017-01-14
    • 1970-01-01
    相关资源
    最近更新 更多