2013-07-04 74 views
0

我努力讓我的WCF Web服務輸出一個wsdl文件,目前爲止沒有運氣(它是空的?)。空白/空WSDL文件

SVC文件:

<%@ ServiceHost Language="C#" Debug="true" Service="xxx.WCF.SubsetMID" CodeBehind="SubsetMID.svc.cs" 
Factory="System.ServiceModel.Activation.WebServiceHostFactory" 
%> 

的CS文件:

namespace xxx.WCF 
{ 
    [ServiceContract(Namespace = "SubsetMID")] 
    public interface ISubsetMID 
    { 
     [OperationContract] 
     [WebInvoke(BodyStyle=WebMessageBodyStyle.Wrapped)] 
     long[] GetMIDs(Guid guid, int subsetID); 
    } 

    [DataContract] 
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)] 
    public class SubsetMID : ISubsetMID 
    { 
     public long[] GetMIDs(Guid guid, int subsetID) 
     { 
      [...] 

      return returnValue; 
     } 
    } 
} 

我的網絡配置文件:

<system.serviceModel> 
    <services> 
    <service name="xxx.WCF.SubsetMID"> 
     <endpoint address="" 
       binding="wsHttpBinding" 
       contract="xxx.WCF.ISubsetMID" /> 

     <endpoint address="mex" 
       binding="mexHttpBinding" 
       contract="IMetadataExchange" /> 
    </service> 
    </services> 
    <behaviors> 
    <serviceBehaviors> 
     <behavior> 
     <serviceMetadata httpGetEnabled="true" /> 
     </behavior> 
    </serviceBehaviors> 
    </behaviors> 
    <serviceHostingEnvironment 
     multipleSiteBindingsEnabled="true" 
     aspNetCompatibilityEnabled="true" 
    /> 
</system.serviceModel> 

,當我訪問WSD我沒有得到任何錯誤(http://.../SubsetMID.svc?wsdl),但它只是一個空白頁。

回答

2

以下是基於我所做的一些研究的最佳猜測 - 我對RESTful WCF服務並不熟悉,所以我可能是錯的,但至少應該給你一個出發點。

你沒有指定,但它看起來像你正在嘗試編寫一個RESTful WCF服務。我不完全確定,因爲您在端點中使用wsHttpBinding,但您也可以使用[WebInvoke]修飾服務中的方法。

在任何情況下,REST服務都沒有WSDL - 這是一件SOAP事情。另外,我相信WCF支持webHttpBinding的REST。當你在你的.svc文件使用WebServiceHostFactory,我覺得是正在發生的事情:

您沒有定義的任何webHttpBinding端點。 WCF將創建一個默認webHttpBinding端點,其地址基於.svc文件的位置。然而,當默認的端點根據WebServiceHost Class使用:

...the WebServiceHost also disables the HTTP Help page and the Web Services Description Language (WSDL) GET functionality so the metadata endpoint does not interfere with the default HTTP endpoint.

如果你正在編寫一個REST服務,您將不再需要一個WSDL。如果您計劃使用SOAP服務,請在您的.svc文件中使用ServiceHostFactory,並從該方法中刪除[WebInvoke]屬性。

再次,這是一個(相對)受過教育的猜測,它可能是錯誤的,但它是一個開始的地方。

+0

我真的不知道我的服務是REST。我想要的只是一種發佈它的方法,並且有一個簡單的方法可以在新項目中引用它。哈拉斯,我能在互聯網上閱讀的是關於自我託管的WCF服務,Google甚至將「svc」翻譯成「wcf」,這使得搜索非常困難。 :( – Serge

+0

然後改變你的.svc文件標記以使用'ServiceHostFactory'並移除服務方法中的[WebInvoke]'屬性應該爲你做竅門。 – Tim

0

我猜你正在使用包含svc文件的wcf服務網站項目。如果你不這樣做,我強烈建議你這樣做,並將其設置爲解決方案中的啓動項目,以便您可以正確調試它。對於我來說,如果你遵循codeproject的一步一步的指示,對你來說也是很好的機會,問題是我沒有引用網站上的wcf服務,因此svc中的指令找不到服務。希望我幫助