2012-01-14 43 views
0

我想爲我創建的Web服務啓用WSDL檢索。我不能叫'通過.svc文件,我提出了Web服務:WCF無法配置WSDL發佈

HTTP://localhost/test.svc

<%@ ServiceHost Language="C#" Debug="true" Service="Project.MyService" CodeBehind="MyService.svc.cs" %> 

調用頁面提供了標準的.NET消息說「元數據此服務的發佈目前已停用。「並附有說明以啓用發佈。

我遵循指示,並添加了web.config條目,但調用http://localhost/test.svc?wsdl產生相同的結果...我怎樣才能啓用我的web服務的WSDL發佈?

的web.config條目

<service name="Project.IMyService" behaviorConfiguration="MyServiceTypeBehaviors" > 
    <endpoint contract="IMetadataExchange" binding="mexHttpBinding" 
       address="mex" 
       /> 
    <host> 
     <baseAddresses> 
     <add baseAddress="http://localhost/test.svc"/> 
     </baseAddresses> 
    </host> 
    </service> 
</services> 
<behaviors> 
    <serviceBehaviors> 
    <behavior name="MyServiceTypeBehaviors"> 
     <serviceMetadata httpGetEnabled="true" /> 
    </behavior> 
    </serviceBehaviors> 
</behaviors> 

回答

2

聽起來很瘋狂,但只是從服務定義andlet行爲匿名(沒有名字)刪除behaviorConfiguration = 「MyServiceTypeBehaviors」。它將保持

<services> 
    <service name="WcfServiceLibrary1.IMyService" > 
    <endpoint contract="IMetadataExchange" binding="mexHttpBinding" 
       address="mex" 
       /> 
    <host> 
     <baseAddresses> 
     <add baseAddress="http://localhost/test.svc"/> 
     </baseAddresses> 
    </host> 
    </service> 
</services> 
<behaviors> 
    <serviceBehaviors> 
    <behavior > 
     <serviceMetadata httpGetEnabled="true" /> 
    </behavior> 
    </serviceBehaviors> 
</behaviors> 
+0

我最終使用了由Visual Studio提供的WCF配置工具。這產生類似於此的結果。謝謝! – Ropstah 2012-01-15 13:13:54

+0

Thx,這隻花了我2個小時。對這些行爲進行命名對我來說已經沒有意義了。 – benvds 2016-04-11 14:35:04