温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

WCF安全中的服务元数据保护方法是什么

发布时间:2021-12-15 09:29:44 来源:亿速云 阅读:132 作者:iii 栏目:编程语言

这篇文章主要讲解了“WCF安全中的服务元数据保护方法是什么”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“WCF安全中的服务元数据保护方法是什么”吧!

WCF安全概述

WindowsCommunicationFoundation(WCF)是Microsoft为构建面向服务的应用程序而提供的统一编程模型,在分布式环境下的WCF安全问题尤为重要,如果你觉得使用了WCF默认的安全措施可以让你高枕无忧,那明天你可就以回家种田了,当然,对于学习来说,足够了~,但我们讲的是真正的项目应用,WCF在各种协议下的安全提供和保证是不尽相同的。

背景

某天,经理老陈对程序员小李说:小李,我们公司外包到一个项目,但是客户要求采用分布式部署,现在项目快接近尾声了,由于我们采用的是WCF,所以在部署的时候出现了一点问题,我们的服务好像谁都能访问得到啊,这是为什么呢?

WCF安全问题呈现

小李***件事就是去查看了服务配置文件,真的是不看不知道,一看吓一跳,原来开发WCF时,采用的都是默认的配置,全是自动生成的代码,没有经过任何的改动,一想到项目将会以这种姿态交付,小李着实捏了一把汗。

Code  <services> <servicenameservicename="WcfServiceLibrary2.Service1"behaviorConfiguration="WcfServiceLibrary2.Service1Behavior"> <host> <baseAddresses> <addbaseAddressaddbaseAddress="http://localhost:8731/Design_Time_Addresses/WcfServiceLibrary2/Service1/"/> </baseAddresses> </host> <endpointaddressendpointaddress=""binding="wsHttpBinding"contract="WcfServiceLibrary2.IService1"> <identity> <dnsvaluednsvalue="localhost"/> </identity> </endpoint> <endpointaddressendpointaddress="mex"binding="mexHttpBinding"contract="IMetadataExchange"/> </service> </services> <behaviors> <serviceBehaviors> <behaviornamebehaviorname="WcfServiceLibrary2.Service1Behavior"> <serviceMetadatahttpGetEnabledserviceMetadatahttpGetEnabled="True"/> <serviceDebugincludeExceptionDetailInFaultsserviceDebugincludeExceptionDetailInFaults="False"/> </behavior> </serviceBehaviors> </behaviors>

解决之道

1、删除元数据交换终结点信息

<endpointaddressendpointaddress="mex"binding="mexHttpBinding"contract="IMetadataExchange"/>

2、将http协议获取元数据重置为:false

<serviceMetadatahttpGetEnabledserviceMetadatahttpGetEnabled="false"/>

3、一般我们都会在开发时配置为元数据据可发现,但是切记,发布你的服务前,一定要删除了,目前,服务在一定范围上得到了保护

4、最终配置如下

<services> <servicenameservicename="WcfServiceLibrary2.Service1"behaviorConfiguration="WcfServiceLibrary2.Service1Behavior"> <host> <baseAddresses> <addbaseAddressaddbaseAddress="http://localhost:8731/Design_Time_Addresses/WcfServiceLibrary2/Service1/"/> </baseAddresses> </host> <endpointaddressendpointaddress=""binding="wsHttpBinding"contract="WcfServiceLibrary2.IService1"> <identity> <dnsvaluednsvalue="localhost"/> </identity> </endpoint> </service> </services> <behaviors> <serviceBehaviors> <behaviornamebehaviorname="WcfServiceLibrary2.Service1Behavior"> <serviceDebugincludeExceptionDetailInFaultsserviceDebugincludeExceptionDetailInFaults="False"/> <serviceDebugincludeExceptionDetailInFaultsserviceDebugincludeExceptionDetailInFaults="False"/></behavior></serviceBehaviors></behaviors>

感谢各位的阅读,以上就是“WCF安全中的服务元数据保护方法是什么”的内容了,经过本文的学习后,相信大家对WCF安全中的服务元数据保护方法是什么这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是亿速云,小编将为大家推送更多相关知识点的文章,欢迎关注!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

wcf
AI