2010-05-02 40 views
2

如何在下面的Web配置中啓用/創建MEX終端,以便從瀏覽器查看服務?在Web.Config中啓用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

在VS,去工具> WCF服務配置編輯器。你可以打開你的web.config並修改你的WCF端點,並綁定在一個不錯的GUI中(不應該)生成VS將會抱怨的XML。

+0

...或者你自己打開該工具;在我的機器上它位於'C:\ Program Files \ Microsoft SDKs \ Windows \ v6.0A \ Bin \ SvcConfigEditor.exe' – josh3736 2010-05-02 20:59:05

+0

嘿josh3736,我剛剛發現這個工具正確:)分鐘 – Conor 2010-05-02 21:00:01

+0

希望我瞭解之前的這個工具,浪費了2天時間,用WCF綁定的web.configs,把它放到了體驗中! – Conor 2010-05-02 21:55:39

2

此行添加到Web.config權下的服務端點:

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

感謝josh3736用於在GUI編輯器中的提示,我唯一的問題是我仍然不知道如何使用編輯要做到這一點,所以這裏是我做過什麼:

  1. 在VS,開放工具/ WCF服務配置編輯器
  2. 打開ŧ他Web.config文件或包含您的服務定義
  3. 導航到服務/(服務)app.config文件/端點文件夾
  4. 如果MetadataEndpoint是存在的,點擊它,編輯配置根據自己的喜好,否則,用鼠標右鍵單擊端點文件夾,然後單擊新服務端點和配置像一個下方的形象。

enter image description here

1

只需添加在你的VS項目的引用System.ServiceModel.dll您的Web.config文件是否存在。

然後添加在Web.config中下面的代碼(像其他服務端點):

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