1

我的 WCF JSONP Web 服务遇到了一个“有趣的”错误。它是我唯一拥有的,它只公开一种方法。如果我在内部通过 Web 浏览器访问我的服务,它会弹出一条消息,实际上 MEX 未启用(真)。如果我从我们的网络外部点击它(就像你会,除非你在我公司的一台机器上)它只是坐在那里,最后超时。URL 是: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

4

1 回答 1

0

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

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

在您的behaviors标签内,添加:

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

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

于 2010-01-16T01:03:23.337 回答