在Web.Config中启用MEX

时间:2010-05-02 20:49:19

标签: wcf wcf-binding

如何在以下Web配置中启用/创建MEX端点,以便从浏览器中查看服务?

我尝试了谷歌搜索的一些变化,但VS总是抱怨它。 (不是有效的子元素等......)

<configuration>
 <system.web>
  <compilation debug="true" targetFramework="4.0" />
  </system.web>
   <system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
    <services>
     <service name="MyApp.MyService" behaviorConfiguration="WebServiceBehavior">
      <endpoint address="" binding="webHttpBinding" contract="MyApp.IMyService"       behaviorConfiguration="JsonBehavior">
        <identity>
          <dns value="localhost"/>
        </identity>
      </endpoint>
    </service>
   </services>
   <behaviors>
   <endpointBehaviors>
      <behavior name="JsonBehavior">
       <webHttp/>
     </behavior>
   </endpointBehaviors>
 </behaviors>
 </system.serviceModel>
 </configuration>

干杯, 康纳

3 个答案:

答案 0 :(得分:2)

在VS中,转到工具&gt; WCF服务配置编辑器。你可以在一个很好的GUI中打开你的web.config并修改你的WCF端点和绑定,这个(不应该)生成VS会抱怨的XML。

答案 1 :(得分:2)

将此行添加到服务端点下的web.config:

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

感谢josh3736对GUI编辑器的提示,我遇到的唯一问题是我仍然不知道如何使用编辑器执行此操作,所以这就是我所做的:

  1. 在VS中,打开 工具/ WCF服务配置编辑器
  2. 打开包含服务定义的web.config或app.config文件
  3. 导航至 服务/(您的服务)/终端 文件夹
  4. 如果 MetadataEndpoint 在那里,请点击它并根据自己的喜好编辑配置,否则,右键点击 端点 文件夹然后点击 新服务端点 ,并配置如下图所示。
  5. enter image description here

答案 2 :(得分:1)

只需在存在Web.config文件的VS Project的引用下添加System.ServiceModel.dll。

然后在Web.config中添加以下代码(与其他服务端点一样):

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