C#WCF在企业防火墙内部工作,但不在外部

时间:2010-01-16 00:49:46

标签: wcf accessibility jsonp mex

我的WCF JSONP Web服务遇到了“有趣”的错误。它是我唯一拥有的,它只暴露一种方法。如果我通过网络浏览器在内部点击我的服务,它会弹出一条消息,实际上,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正常工作
  3. 注意:我使用的是此处的JSONP类:http://msdn.microsoft.com/en-us/library/cc716898.aspx

1 个答案:

答案 0 :(得分:0)

要启用MEX,请在service标记内添加:

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

behaviors标记内添加:

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

关于无法从外部访问该服务的原因,这可能是防火墙问题吗?

相关问题