Enable MEX in a Web.Config

本小妞迷上赌 提交于 2019-12-02 05:17:19

问题


How do I enable/create a MEX endpoint in the below web config so I can view the service from my browser?

I have tried a few variation from googling but VS always complains about it. (not a valid child element etc...)

<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>

Cheers, Conor


回答1:


In VS, go Tools > WCF Service Configuration Editor. You can open your web.config and tinker with your WCF endpoints and bindings in a nice GUI that (shouldn't) generate XML that VS will complain about.




回答2:


Add this line to the web.config right under the service endpoint:

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

Thanks josh3736 for the tip on the GUI editor, the only problem I had was I still didn't know how to use the editor to do this, so here is what I did:

  1. In VS, open Tools/WCF Service Configuration Editor
  2. Open the web.config or app.config file that contains your service definition
  3. Navigate to the Services / (your service) / Endpoints folder
  4. If the MetadataEndpoint is there, click on it and edit the configuration to your liking, otherwise, right-click the Endpoint folder then click New Service Endpoint and configure like the one in the image below.




回答3:


Just add System.ServiceModel.dll under references of your VS Project where your Web.config file is present.

Then add the below code in Web.config(like other service endpoints):

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


来源:https://stackoverflow.com/questions/2754923/enable-mex-in-a-web-config

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!