.net 解决 WCF 错误:此服务的元数据发布当前已禁用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6290323/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 15:37:43  来源:igfitidea点击:

Solve WCF Error: Metadata publishing for this service is currently disabled

.netwcfweb-servicesbindingweb-config

提问by Adrian Hedley

I want to publish a Webservice with custom binding configuration. I am using a custom binding configuration to increase the default message size of 65536 bytes. The problem I am having is that when I use the web.config settings as shown below, I am getting an error:

我想发布具有自定义绑定配置的 Web 服务。我正在使用自定义绑定配置来增加 65536 字节的默认消息大小。我遇到的问题是,当我使用如下所示的 web.config 设置时,出现错误:

Metadata publishing for this service is currently disabled.

此服务的元数据发布当前已禁用。

My Main goal is to be able to increase the default message size, therefore any other config is welcome, however I was trying to keep it as simple as possible to avoid further issues.

我的主要目标是能够增加默认消息大小,因此欢迎使用任何其他配置,但是我试图使其尽可能简单以避免出现更多问题。

Can you please spot what is wrong with my configuration?

你能找出我的配置有什么问题吗?

<bindings>
  <basicHttpBinding>        
      <binding name="NewBinding0" closeTimeout="00:10:00" openTimeout="01:10:00"
     receiveTimeout="01:10:00" sendTimeout="01:10:00" maxBufferSize="99536"
     maxBufferPoolSize="5242880" maxReceivedMessageSize="99536">
        <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
          maxArrayLength="99536" maxBytesPerRead="99536" maxNameTableCharCount="2147483647" />
        <security>
          <transport clientCredentialType="Basic" />
        </security>

    </binding>
  </basicHttpBinding>
</bindings>
<behaviors>
  <serviceBehaviors>
    <behavior name="MeterReadingOrderWSBehaviors">
      <serviceMetadata httpsGetEnabled="true" />         
    </behavior>
    </serviceBehaviors>

</behaviors>
<services>
  <service name="MeterReadingOrderWS.IMeterReadingOrderWS" behaviorConfiguration="MeterReadingOrderWSBehaviors">
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:3440/MeterReadingOrderWS.svc"/> 
      </baseAddresses>
    </host>
    <endpoint address="" contract="MeterReadingOrderWS.IMeterReadingOrderWS" binding="basicHttpBinding" bindingConfiguration="NewBinding0" />
    <endpoint address="mex" contract="IMetadataExchange" binding="mexHttpsBinding" />
  </service>
</services>

回答by Adrian Hedley

I have continued my research and followed this article which solved my problem:

我继续我的研究,并按照这篇文章解决了我的问题:

http://keithelder.net/2008/01/17/exposing-a-wcf-service-with-multiple-bindings-and-endpoints/

http://keithelder.net/2008/01/17/exposing-a-wcf-service-with-multiple-bindings-and-endpoints/

Hope it can help others as well.

希望它也可以帮助其他人。

回答by manoj prajapati

Note that your problem is seems to be related with Metadata behaviour, before that you have to check name of service i.e.WebApplication1.MyService in below code; this should be in same order namespace.service

请注意,您的问题似乎与元数据行为有关,在此之前您必须在下面的代码中检查服务名称 ieWebApplication1.MyService;这应该是相同的顺序 namespace.service

    <endpoint  address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="MyServiceBebavior">
      <serviceMetadata  httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<!--<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />-->

回答by Arian

Add behavior for your Service and enable

为您的服务添加行为并启用

httpGetEnabled=true

httpGetEnabled=true

like this:

像这样:

 <behavior name="MyService.Service1Behavior">
     <serviceMetadata httpGetEnabled="true" />
 </behavior>

回答by LoSciamano

<serviceMetadata httpsGetEnabled="true" />

You've enabled metadata service through httpsbut you have a httpendpoin for mexHttpsBinding. You have to use https for you endpoint address.

您已通过https启用元数据服务,但您有一个用于 mexHttpsBinding的http端点。您必须为端点地址使用 https。



Edit

编辑

You use mexHttpsBinding so it's correct to use httpsGetEnabled. If you don't want https for metadata use httpGetEnabled and change binding type for mex from mexHttpsBinding to mexHttpBinding.

您使用 mexHttpsBinding,因此使用 httpsGetEnabled 是正确的。如果您不希望 https 用于元数据,请使用 httpGetEnabled 并将 mex 的绑定类型从 mexHttpsBinding 更改为 mexHttpBinding。

    <endpoint address="mex" contract="IMetadataExchange" binding="mexHttpBinding" />
    <!--- ......- -->
    <serviceBehaviors>
       <behavior name="MeterReadingOrderWSBehaviors">
            <serviceMetadata httpGetEnabled="true" />         
       </behavior>
   </serviceBehaviors>

If you want to use https for metadata consider to use a full address notation per your mex endpoint

如果您想将 https 用于元数据,请考虑使用每个 mex 端点的完整地址表示法

<endpoint address="https://localhost:3440/MeterReadingOrderWS.svc/mex" contract="IMetadataExchange" binding="mexHttpsBinding" />