简体   繁体   English

在WCF Rest Web服务上启用HTTPS

[英]Enable HTTPS on WCF rest webservice

Enable HTTPS on WCF rest webservice 在WCF Rest Web服务上启用HTTPS

I've already tried multiple configuration but i'm not able to get my WCF rest webservice working via HTTPS. 我已经尝试了多种配置,但是无法通过HTTPS使WCF rest网络服务正常工作。 I get 500 internal errors, or 400 bad request. 我收到500个内部错误或400个错误的请求。

I've added a new website into IIS, binded to port 80 and 443. Then, enabled http/https protocols. 我在IIS中添加了一个新网站,并将其绑定到端口80和443。然后启用了http / https协议。

Here's my Web.config: 这是我的Web.config:

<?xml version="1.0"?>
<configuration>
  <system.serviceModel>
    <services>
   <service name="RestService.MyService">
     <endpoint address="https://mywebsite.com"
       binding="webHttpBinding" contract="RestService.IMyService" />
   </service>
 </services>
    <behaviors>
      <endpointBehaviors>
        <behavior>
          <webHttp/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
  </system.serviceModel>
  <startup>
    <supportedRuntime version="v4.5" sku=".NETFramework,Version=v4.5.1"/>
  </startup>
  <system.diagnostics>
    <sources>
      <source name="System.ServiceModel" switchValue="Information,ActivityTracing"
        propagateActivity="true">
        <listeners>
          <add name="xml" />
        </listeners>
      </source>
      <source name="System.ServiceModel.MessageLogging">
        <listeners>
          <add name="xml" />
        </listeners>
      </source>
    </sources>
    <sharedListeners>
      <add initializeData="C:\logs\TracingAndLogging-service.svclog" type="System.Diagnostics.XmlWriterTraceListener"
        name="xml" />
    </sharedListeners>
    <trace autoflush="true" />
  </system.diagnostics>
</configuration>

Try to add the following binding configuration to the endpoint. 尝试将以下绑定配置添加到端点。

<services>
  <service name="WcfServiceFile.Service1">
    <endpoint address="" binding="webHttpBinding" contract="WcfServiceFile.IService1" behaviorConfiguration="beh" bindingConfiguration="myBinding">
    </endpoint>
  </service>
</services>
<bindings>
  <webHttpBinding >
    <binding name="myBinding" >
      <security mode="Transport">
        <transport clientCredentialType="None"></transport>
      </security>
    </binding>
  </webHttpBinding>

Don't forget to apply the bindingconfiguration to the endpoint so that it could take effect. 不要忘记将绑定配置应用于端点,以便它可以生效。
Result. 结果。 在此处输入图片说明 Due to the Self-signed certificate, the connection is not secure. 由于存在自签名证书,因此连接不安全。 Feel free to contact me if the problem still exists. 如果问题仍然存在,请随时与我联系。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM