WCF休息服务http到https错误404

时间:2017-08-14 08:07:46

标签: c# rest wcf ssl https

我正在使用Visual Studio 2015.我有一个Xamarin Cross-Platfom的项目。 我的WCF Rest服务可以正常使用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 Rest服务?我错过了什么吗?

My_WCF_proprieties

1 个答案:

答案 0 :(得分: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

它有效:)