代码之家  ›  专栏  ›  技术社区  ›  Overhed

WCF Web服务元数据发布已禁用错误

  •  0
  • Overhed  · 技术社区  · 15 年前

    我修改了web.config以添加自定义绑定,以增加缓冲区和消息的大小,并且似乎在显式创建服务元素时,它以某种方式破坏了对behavior元素的引用。

    当我尝试使用wcf测试客户机从vs运行我的Web服务时,或者我转到服务页面时,我得到错误:

    Metadata publishing for this service is currently disabled.
    

    我已经将web.config与几个不同的源文件进行了比较,所有内容似乎都匹配。我不知道是什么问题。

    以下是system.serviceModel元素:

    <system.serviceModel>    
    <services>
      <service name="BIMIntegrationWS.BIMIntegrationService" behaviorConfiguration="metadataBehavior">
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <endpoint address="http://localhost:1895/BIMIntegrationService.svc" 
                  binding="customBinding" bindingConfiguration="customBinding0" 
                  contract="BIMIntegrationWS.IBIMIntegrationService"/>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="metadataBehavior">
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <customBinding>
        <binding name="customBinding0">
          <binaryMessageEncoding />
          <httpTransport maxReceivedMessageSize="262064"
                       maxBufferSize="262064"
                       maxBufferPoolSize="262064" />
        </binding>
      </customBinding>
    </bindings>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true"  aspNetCompatibilityEnabled="true"/>
    

    似乎Web服务页面没有找到元素。我不会有错误抱怨目标行为配置不存在,或者类似的情况,只是元数据发布没有启用。

    任何帮助都将不胜感激。

    谢谢。

    2 回复  |  直到 12 年前
        1
  •  2
  •   Overhed    15 年前

    我想我已经“解决”了这个问题。以后还会有更多。

    编辑: 为了“修复”我的问题,我基本上在我的应用程序中添加了一个新的WCF服务,并让它实现我以前的接口,然后我从原始服务中复制了所有代码,当我调整.config文件(看起来很像问题中发布的文件)时,一切都正常。

    当然,我知道,就像我们都知道的,这里没有魔法,一定存在一些差异。这是我注意到/记得的时候,在我创建了名为“bimIntegrationService.svc”的原始服务之后,我决定这个名称太长,所以我将类重命名/重构为“bimIntegrationws”。但是,这样做不会更改服务文件的名称(因此也不会更改http://address中文件的名称)。

    长话短说,我对.config进行了两次更改,一切正常:

    1)我改变了:

    <service name="BIMIntegrationWS.BIMIntegrationService" behaviorConfiguration="metadataBehavior">
    

    <service name="BIMIntegrationWS.BIMIntegrationWS" behaviorConfiguration="metadataBehavior">
    

    像这样运行服务之后,我得到一个错误(这次是一个很有用的错误),它抱怨如果启用了多个esitebindings,则端点地址必须是相对的。所以:

    2)我把它设为假(因为我不记得为什么一开始就在那里),一切都很好。

    我想当我的Web服务看起来根本没有使用我的“服务”元素时,我应该得到一个提示。:

    编辑2:

    实际上,在我的第二条评论中,在最初的问题中,您可以看到自动生成的标记指向:而不是“bimIntegrationService”。 那本该把它送出去的。

    我怀疑其他人也会有同样的问题,但以防万一。

        2
  •  0
  •   Dark Falcon    12 年前

    我也遇到过同样的问题;我已经正确地配置了所有的东西(甚至从以前运行的服务中复制了代码),但是在允许服务公开元数据方面没有任何改变。但是,如果我对app.config犯了拼写错误、解析错误等错误,我会得到一些异常,告诉我要纠正这个问题(这告诉我服务正在读取配置,只是忽略了它)。

    我可以通过在主机应用程序中生成配置设置来绕过它:

    System.ServiceModel.Description.ServiceMetadataBehavior smb = new System.ServiceModel.Description.ServiceMetadataBehavior();
    smb.HttpGetEnabled = true;
    ServiceBase host = new Servicebase(typeof(MyService), new Uri("http://localhost:1234/"));
    host.Description.Behaviors.Add(smb);
    host.Open();
    
    ...
    
    host.Close();
    

    基本上允许代码重写并推送我想要应用的配置文件更改。我知道这不理想,但是我通过一个Windows服务来公开这个服务,这使得它能够做到。如果你确实解决了你的问题,请把解决方案传给我,因为我很想知道为什么(至少在你的情况下,如果不是我们的情况下)失败了。

    推荐文章