c# – 如何隐藏我的WCF服务
发布时间:2020-12-16 01:39:26 所属栏目:百科 来源:网络整理
导读:我有一个嵌入到 Windows服务中的WCF服务.它绑定到localhost但它也接受来自这种URL的连接 – “http:// ip:port / ServiceName”,如何将其隐藏起来并允许仅从localhost连接. 这是我的服务配置 system.serviceModel behaviors serviceBehaviors behavior nam
我有一个嵌入到
Windows服务中的WCF服务.它绑定到localhost但它也接受来自这种URL的连接 – “http:// ip:port / ServiceName”,如何将其隐藏起来并允许仅从localhost连接.
这是我的服务配置 <system.serviceModel> <behaviors> <serviceBehaviors> <behavior name="Test.Service.ServiceBehavior"> <serviceMetadata httpGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="true" /> </behavior> </serviceBehaviors> </behaviors> <services> <service behaviorConfiguration="Test.Service.ServiceBehavior" name="Test.Service.TestService"> <endpoint address="localhost" binding="wsHttpBinding" contract="Test.Service.IService"> <identity> <dns value="localhost" /> </identity> </endpoint> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> <host> <baseAddresses> <add baseAddress="http://localhost:8732/MyService/service" /> </baseAddresses> </host> </service> </services> </system.serviceModel> 解决方法
要“隐藏”它,您需要关闭任何元数据交换,因此您需要删除:
<serviceMetadata httpGetEnabled="true" /> 从您的服务行为,您需要删除mex端点: <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 然而,这只是“模糊”它.为了避免除localhost之外的其他任何人调用 – 为什么不切换到netNamedPipeBinding,这是设计“仅在这台机器上” – 没有外部调用者能够调用该端点. 否则,您必须检查呼叫者的IP地址并根据该信息阻止它们 – 但这可能很容易被欺骗…. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |