【问题标题】:C# WCF works inside corporate firewall but not outsideC# WCF 在企业防火墙内部工作,但不在外部
【发布时间】:2011-01-05 18:04:32
【问题描述】:

我的 WCF JSONP Web 服务遇到了一个“有趣的”错误。它是我唯一拥有的,它只公开一种方法。如果我通过网络浏览器 internally 访问我的服务,它会弹出一条消息,实际上 MEX 未启用 (true)。如果我从我们的网络外部点击它(就像你会,除非你在我公司的一台机器上)它只是坐在那里,最后超时。网址是:http://demo.rivworks.com/services/Negotiate.svc。关于可能导致此行为的任何想法?

这是 web.config:

  <!-- WCF configuration -->
  <system.serviceModel>
    <behaviors>
      <endpointBehaviors>
        <behavior name="JsonpServiceBehavior">
          <webHttp />
        </behavior>
      </endpointBehaviors>
    </behaviors>

    <services>
      <service name="RivWorks.Web.Service.NegotiateService">
        <endpoint address=""
                binding="customBinding"
                bindingConfiguration="jsonpBinding"
                behaviorConfiguration="JsonpServiceBehavior"
                contract="RivWorks.Web.Service.INegotiateService" />
      </service>
    </services>

    <extensions>
      <bindingElementExtensions>
        <add name="jsonpMessageEncoding" type="RivWorks.Web.Service.JSONPBindingExtension, RivWorks.Web.Service, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
      </bindingElementExtensions>
    </extensions>

    <bindings>
      <customBinding>
        <binding name="jsonpBinding" >
          <jsonpMessageEncoding />
          <httpTransport manualAddressing="true"/>
        </binding>
      </customBinding>
    </bindings>    
  </system.serviceModel>
</configuration>

代码如下:

namespace RivWorks.Web.Service
{
    //----------------------------------------------------------------------------------------------------------//
    // Data class                                                                                               //
    //----------------------------------------------------------------------------------------------------------//
    [DataContract(Name = "NegotiateSetup", Namespace = "http://rivworks.com/DataContracts/2009/01/15")]
    public class NegotiateSetup : INegotiationInitialize
    {
        #region Declarations
        ...
        #endregion


        #region INegotiationInitialize Members
        ...
        #endregion
    }

    //----------------------------------------------------------------------------------------------------------//
    // Service Implementation                                                                                   //
    //----------------------------------------------------------------------------------------------------------//
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class NegotiateService : INegotiateService
    {
        public NegotiateService() { }

        public INegotiationInitialize GetSetup(string method, string jsonInput)
        {
            ...
            return resultSet;
        }
    }
}

我在这里做了几件事:

  1. 为什么我不能从我的本地网络之外点击它?
  2. 如何让 MEX 正常工作

注意:我正在使用此处找到的 JSONP 类:http://msdn.microsoft.com/en-us/library/cc716898.aspx

【问题讨论】:

  • 您是否排除了防火墙规则?例如,如果你在那台机器上放置一个静态页面,你能从防火墙外访问它吗?
  • 答案似乎是否定的。我应该能够点击demo.rivworks.com/login.aspx,但我不能,而且它也会超时。这是一个 RackSpace 服务器,所以星期一我将与他们一起输入故障单。
  • 嗨,Keith,这听起来像是防火墙问题。鉴于您根本无法达到终点,这表明它与 WCF 本身无关。另一个简单的测试是删除一个简单的 HelloWorld 文本文件或一个简单的 html 文件,看看你是否可以点击它。

标签: wcf accessibility jsonp mex


【解决方案1】:

要启用您的 MEX,请将其添加到您的 service 标签中:

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

在您的behaviors 标签内,添加:

  <serviceBehaviors>
    <behavior name="JsonpServiceBehavior">
      <serviceMetadata httpGetEnabled="true"/>
    </behavior>
  </serviceBehaviors>

关于为什么无法从外部访问该服务,这可能是防火墙问题吗?

【讨论】:

  • 我们发现我们的托管公司“因为 SSL 冲突”更改了这个特定站点的 IP 地址——尽管它已经稳定运行了将近一年。我们有一个中间证书失败,不得不重新安装我们的通配符证书。用于将主机标头映射到端口 443 (SSL) 的命令行脚本之一未运行。当 IIS 最终循环应用程序池时,出现了故障。 Rackspace 更改了一些 IP,但没有正确重新映射证书。因此,这让我面临 MEX 挑战,而这个答案现在似乎可以解决。谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-11-29
  • 2010-09-16
  • 2019-02-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多