【问题标题】:How to hide my WCF service如何隐藏我的 WCF 服务
【发布时间】:2010-11-24 10:54:46
【问题描述】:

我在 Windows 服务中嵌入了 WCF 服务。它绑定到本地主机,但它也接受来自这种 URL 的连接 - “http://ip:port/ServiceName”,我怎样才能对其他人隐藏它并只允许来自本地主机的连接。

这是我的服务配置

<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>

【问题讨论】:

    标签: c# wcf service wcf-binding svc


    【解决方案1】:

    要“隐藏”它,你需要关闭任何元数据交换,所以你需要移除:

    <serviceMetadata httpGetEnabled="true" /> 
    

    从您的服务行为中,您需要删除 mex 端点:

    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
    

    但是,这只是“模糊”它。为了避免除 localhost 之外的任何其他人调用 - 为什么不切换到 netNamedPipeBinding,这是“仅在这台机器上”的设计 - 没有外部调用者能够调用该端点。

    否则,您必须检查调用者的 IP 地址并根据该信息阻止它们 - 但是很容易被欺骗......

    【讨论】:

      【解决方案2】:

      我会切换到NetNamedPipeBinding - 这本质上是仅限本地的,但也避免了一些额外的层,并且不需要访问任何端口(默认情况下非管理员没有)。这可以使用&lt;netNamedPipeBinding&gt; 元素在配置中完成。

      【讨论】:

        【解决方案3】:

        如果您在 IIS 中托管,您只需将站点绑定从“*”更改为“127.0.0.1”

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2010-10-19
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多