如何为WCF服务启用元数据发布 [英] How to enable Metadata publishing for WCF service

查看:148
本文介绍了如何为WCF服务启用元数据发布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了在IIS上托管的WCF服务。浏览服务时出现以下错误。



此服务的元数据发布目前已停用。



以下是web.config的代码



I have created WCF service hosted on IIS. I get the following error when browse the service.

Metadata publishing for this service is currently disabled.

Here is the code for web.config

<?xml version="1.0"?>
<configuration>
    <system.web>
        <compilation debug="true" targetFramework="4.0"/>
    </system.web>
    <system.serviceModel>
        <services>
            <service behaviorConfiguration="ServiceBehavior" name="IISHostedServiceEx1.MyService">
                <endpoint address="http://localhost/IISHostedServiceEx1/MyService.svc" binding="wsHttpBinding" contract="IMyService">
                    <identity>
                        <dns value="localhost"/>
                    </identity>
                </endpoint>
                <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
            </service>
        </services>
        <behaviors>
            <serviceBehaviors>
                <behavior name="ServiceBehavior">
                    <!-- 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="false"/>
                </behavior>
            </serviceBehaviors>
        </behaviors>
    </system.serviceModel>


    <system.webServer>
        <modules runAllManagedModulesForAllRequests="true"/>
    </system.webServer>
</configuration>





可以任何身体都告诉我如何解决它?



提前感谢。



Can any body tell me how can i resolve it?

thanks in advance.

推荐答案

右键单击您的服务引用,然后单击配置并取消选中重用参考程序集中的类型。

第二件事你需要一个额外端点ImetaDataExchange,如果不存在则添加web.config。

< endpoint address =mexbinding =mexHttpBindingcontract =IMetadataExchange>
Right click on your service reference and click configure and un-check "Reuse Types in Referenced Assemblies".
Second thing you need to have one extra endpoint ImetaDataExchange, If its not there then add in web.config.
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange">


我认为问题是你用于wsHttpBinding元素的地址。

一般来说,没有必要指定地址,除非你真的希望它在子地址中运行实际的.svc文件,如下所示:



I believe the problem is the address you're using for the wsHttpBinding element.
Generally, there's no need to specify the address, unless you actually want it to run in a subaddres of the actual .svc file, as below:

<system.serviceModel>
  <services>
    <service behaviorConfiguration="ClientProcessadorEventos" name="ClienteExternoWS.ClientProcessadorEventos">
      <endpoint address="mex" binding="mexHttpBinding" name="Mex" contract="ServiceInterfaces.IProcessadorEventos"/>
      <endpoint address="basic" binding="basicHttpBinding" name="Basic" contract="ServiceInterfaces.IProcessadorEventos"/>
      <endpoint address="" binding="wsHttpBinding" name="Ws" contract="ServiceInterfaces.IProcessadorEventos"/>
    </service>
  </services>
  <behaviors>
    <serviceBehaviors>
      <behavior name="ClientProcessadorEventos">
        <serviceMetadata httpGetEnabled="true"/>
      </behavior>
    </serviceBehaviors>
  </behaviors>
</system.serviceModel>





在这种情况下,我的服务公开同样的合同在纯.svc地址(root,因为没有指定地址),它也在[ServiceName] .svc / Basic地址公开为basicBinding。



In this case, my service exposes the same contract on the pure .svc address (root, as the address is not specified), and it also exposes as basicBinding on the [ServiceName].svc/Basic address.


这篇关于如何为WCF服务启用元数据发布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆