2013-12-19 86 views
0

錯誤WCF WebService的錯誤

Error: Cannot obtain Metadata from localhost:81/WebServices/Legacy.svc If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address. For help enabling metadata publishing, please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange Error URI: localhost:81/WebServices/Legacy.svc Metadata contains a reference that cannot be resolved: 'localhost:81/WebServices/Legacy.svc'.

我的web.config

<system.serviceModel> 
    <services> 
     <service name="Web.WebServices.Legacy" behaviorConfiguration="serviceBehaviorsZero"> 
      <endpoint address="" 
         name="SspService" 
         binding="basicHttpBinding" 
         bindingConfiguration="basicHttpBindingZero" 
         contract="Web.WebServices.ILegacy" /> 

      <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" /> 
     </service> 
    </services> 
    <bindings> 
     <basicHttpBinding> 
      <binding name="basicHttpBindingZero"> 
       <security mode="None"> 
       </security> 
      </binding> 
     </basicHttpBinding> 

    </bindings> 
    <behaviors> 
     <serviceBehaviors> 
      <behavior name="serviceBehaviorsZero"> 
       <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" /> 
       <serviceDebug includeExceptionDetailInFaults="false" /> 
      </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /> 
</system.serviceModel> 

爲什麼我不能夠訪問使用WCF測試客戶端我的web服務?

當我通過URL本地主機接取:81/Web服務/ Legacy.svc在瀏覽器 我得到這個錯誤 文件名,目錄名或卷標語法不正確。

更新:我的.svc文件代碼

<%@ ServiceHost Language="C#" Debug="true" Service="Web.WebServices.Legacy" CodeBehind="Legacy.svc.cs" %> 

[ServiceBehavior(AddressFilterMode = AddressFilterMode.Any)] 
    public class Legacy : ILegacy 
    { 
     public string DoWork() 
     { 
      return "https"; 
     } 
    } 
+0

您能否顯示.svc文件的內容? – Chris

+0

您有'mexHttpsBinding' - 可能將其更改爲'mexHttpBinding',或將測試客戶端更改爲指向本地HTTPS端點? – StuartLC

+0

@克里斯: 標記:<%@ ServiceHost的語言= 「C#」 調試= 「真」 服務= 「MvcApplication4.WS.Service1」 代碼隱藏= 「Service1.svc.cs」 %> C#代碼: 命名空間的Web .WebServices { [ServiceBehavior(AddressFilterMode = AddressFilterMode。任何)] 公共類傳統:ILegacy { 公共字符串DoWork() { return「OK」; } } } –

回答

0
  1. 將只是簡單的文件在網站目錄(hello.html的),並檢查是否可達(的helloworld.html)

    的Hello World 的Hello World!

如果不工作 - 檢查IIS的綁定設置,以及該服務是否和它的應用程序池上。

  1. 在IIS配置上,選擇'功能視圖',然後轉到'目錄瀏覽'+啓用。
  2. 在svc放完之後:... svc?wsdl
  3. 首先檢查一下你自己的本地環境。一切正常後,您可以從網上查詢。
  4. 在Visual Studio上,您應該通過創建新網站(新文件夾)並將結果複製到網站(包括web.config)來完成基本操作 - 有一個默認的源代碼。你可以添加新的函數來服務(即helloworld,它返回一個字符串,並在iservices上引用它)。 如果沒有創建svc文件(舊的VS版本) - 你可以創建自己的文本文件,並做一些複製+粘貼修復svc文件...在網站上,應該有app_code和app_data文件夾。

希望有所幫助。 祝你好運!