如何在 WCF RESTful 服务上启用 HTTPS?
How to enable HTTPS on WCF RESTful Service?
如何使 wcf 在 https 上工作。我想通过 https 使用此 wcf 我已经搜索了很多文章我没有得到答案请帮助我是 wcf 概念的新手。我想从 ajax,jquery
调用它
<system.serviceModel >
<services>
<service
name="WcfRestfulService.HttpService" behaviorConfiguration="ServiceBehaviour" >
<endpoint address="" binding="webHttpBinding" behaviorConfiguration="web"
contract="WcfRestfulService.IHttpService">
</endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehaviour">
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata 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="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
您需要在绑定中设置security mode="Transport"
<basicHttpBinding>
<binding name="secureHttpBinding">
<security mode="Transport">
<transport clientCredentialType="None"/>
</security>
</binding>
</basicHttpBinding>
阅读更多关于MSDN
您似乎正在使用 WCF 构建 RESTful 服务,并且您非常接近 保护它。
您需要执行以下操作来保护它:
- 添加安全模式设置为
Transport
的新 WebHttpBinding
配置。
- 将新的
WebHttpBinding
配置分配给您的服务端点绑定。
- 通过设置
httpGetEnabled="false"
. 确保您的 RESTful 服务只能通过 HTTPS 访问
- 设置元数据发布端点以使用 HTTPS。
这些更改全部汇总在修改后的配置文件中(请参阅更改点的注释)。另请注意,您的服务端点必须使用 HTTPS 方案而不是 HTTP。
<system.serviceModel >
<services>
<service name="WcfRestfulService.HttpService"
behaviorConfiguration="ServiceBehaviour" >
<endpoint address=""
binding="webHttpBinding"
<!-- Add reference to secure WebHttpBinding config -->
bindingConfiguration="webHttpTransportSecurity"
behaviorConfiguration="web"
contract="WcfRestfulService.IHttpService" />
<!-- Need to make sure that our metadata
publishing endpoint is using HTTPS as well -->
<endpoint address="mex"
binding="mexHttpsBinding"
contract="IMetadataExchange" />
</service>
</services>
<!-- Add secure WebHttpBinding config -->
<bindings>
<webHttpBinding>
<binding name="webHttpTransportSecurity">
<security mode="Transport" />
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehaviour">
<serviceMetadata httpsGetEnabled="true"
<!-- Make sure the service can
be accessed only via HTTPS -->
httpGetEnabled="false"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
我遇到了同样的问题,但想测试 HTTP get 请求,因为我的服务是内部服务。
记得同时启用 HTTPS。 httpsGetEnabled="true"
下面以我的配置为例:
<bindings >
<basicHttpBinding>
<binding name="secureHttpBinding" >
<security mode="Transport" />
</binding>
</bindings>
.....
<behaviors>
<serviceBehaviors>
<behavior >
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
如何使 wcf 在 https 上工作。我想通过 https 使用此 wcf 我已经搜索了很多文章我没有得到答案请帮助我是 wcf 概念的新手。我想从 ajax,jquery
调用它 <system.serviceModel >
<services>
<service
name="WcfRestfulService.HttpService" behaviorConfiguration="ServiceBehaviour" >
<endpoint address="" binding="webHttpBinding" behaviorConfiguration="web"
contract="WcfRestfulService.IHttpService">
</endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehaviour">
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata 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="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
您需要在绑定中设置security mode="Transport"
<basicHttpBinding>
<binding name="secureHttpBinding">
<security mode="Transport">
<transport clientCredentialType="None"/>
</security>
</binding>
</basicHttpBinding>
阅读更多关于MSDN
您似乎正在使用 WCF 构建 RESTful 服务,并且您非常接近 保护它。
您需要执行以下操作来保护它:
- 添加安全模式设置为
Transport
的新WebHttpBinding
配置。 - 将新的
WebHttpBinding
配置分配给您的服务端点绑定。 - 通过设置
httpGetEnabled="false"
. 确保您的 RESTful 服务只能通过 HTTPS 访问
- 设置元数据发布端点以使用 HTTPS。
这些更改全部汇总在修改后的配置文件中(请参阅更改点的注释)。另请注意,您的服务端点必须使用 HTTPS 方案而不是 HTTP。
<system.serviceModel >
<services>
<service name="WcfRestfulService.HttpService"
behaviorConfiguration="ServiceBehaviour" >
<endpoint address=""
binding="webHttpBinding"
<!-- Add reference to secure WebHttpBinding config -->
bindingConfiguration="webHttpTransportSecurity"
behaviorConfiguration="web"
contract="WcfRestfulService.IHttpService" />
<!-- Need to make sure that our metadata
publishing endpoint is using HTTPS as well -->
<endpoint address="mex"
binding="mexHttpsBinding"
contract="IMetadataExchange" />
</service>
</services>
<!-- Add secure WebHttpBinding config -->
<bindings>
<webHttpBinding>
<binding name="webHttpTransportSecurity">
<security mode="Transport" />
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehaviour">
<serviceMetadata httpsGetEnabled="true"
<!-- Make sure the service can
be accessed only via HTTPS -->
httpGetEnabled="false"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
我遇到了同样的问题,但想测试 HTTP get 请求,因为我的服务是内部服务。
记得同时启用 HTTPS。 httpsGetEnabled="true"
下面以我的配置为例:
<bindings >
<basicHttpBinding>
<binding name="secureHttpBinding" >
<security mode="Transport" />
</binding>
</bindings>
.....
<behaviors>
<serviceBehaviors>
<behavior >
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>