2011-02-07 26 views
31

我在瀏覽器中瀏覽服務時收到元數據錯誤。我不與客戶WCF當前禁用此服務的元數據發佈+內容類型錯誤

和Yes。我加入<serviceMetadata httpGetEnabled="True"/>消費它,我有一個MEX終結定義

,但它仍然不會工作..

所以我創建了一個準系統服務在IIS7上託管。全新安裝Windows 7和VS2010。

我採納了這個頁面的指示信:

http://msdn.microsoft.com/en-us/library/ms733766.aspx

我相信,這已經是某種配置問題與IIS7,但並不能確定。這是我的服務設置:

編輯:

我試圖訪問與SvcUtil工具的服務,得到了以下錯誤:

The remote server returned an error: (415) Cannot process the message because the content type 'application/soap+xml; charset=utf-8' was not the expected type 'text/xml; charset=utf-8'.. 

,它也說:The HTML document does not contain Web service discovery information.

不知道如何解決它,但是..

.svc文件:

<%@ServiceHost language="C#" Debug="true" Service="DestructionServices.TacticalNukeSVC「%>

cs文件(位於C:\發展\ HostedDestructionServices \ App_Code文件夾):

using System; 
using System.ServiceModel; 

namespace DestructionServices 
{ 
    [ServiceContract] 
    public interface INukeInterface 
    { 
     [OperationContract] 
     string FireMissile(); 

     [OperationContract] 
     string DirectFire(double x, double y, double z); 

     [OperationContract] 
     void EnterCoordinates(double x, double y, double z); 
    } 

    public class TacticalNukeSVC : INukeInterface 
    { 
     public string FireMissile() 
     { 
      return "Boom"; 
     } 

     public void EnterCoordinates(double x, double y, double z) 
     { 
      //bah, who cares about coordinates.. 
     } 

     public string DirectFire(double x, double y, double z) 
     { 
      return "Fired at: " + x + ", " + y + ", " + z; 
     } 
    } 
} 

Web.Config中:

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
    <system.serviceModel> 
    <services> 
     <service name="DestructionServices.Destro" behaviorConfiguration="MetadataBehavior"> 
     <endpoint address="" binding="wsHttpBinding" contract="DestructionServices.INukeInterface" /> 
     <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
     </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="MetadataBehavior"> 
      <serviceDebug includeExceptionDetailInFaults="True" httpHelpPageEnabled="True" /> 
      <serviceMetadata httpGetEnabled="True"/> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    </system.serviceModel> 
</configuration> 

IIS

+1

也加入了baseAddress節點得到由IIS – KevinDeus 2011-02-07 03:09:02

+0

是的,如果你在IIS託管,指定的基址是沒有實際意義的,因爲IIS將忽略決定你的服務在哪裏... – 2011-02-07 06:05:32

回答

69

你的代碼和配置似乎很好 - 除了一點點:

在你<service>標籤,您已經定義似乎並不對應於實際實現服務類的名稱:

<service name="DestructionServices.Destro" ......> 
       ************************** 

但你的類是:

namespace DestructionServices 
{ 
    ..... 
    public class TacticalNukeSVC : INukeInterface 
    { 

這些名字需要比賽!在配置<service>標籤的name=屬性必須是正是您的服務類叫做 - 完全合格,其中包括命名空間 - 所以你的情況在這裏,它應該是:

<service name="DestructionServices.TacticalNukeSVC" ......> 
0

遇到了類似的問題。我在web.config中的服務標籤中使用了錯誤的命名空間,而svc文件中的服務類的命名空間不正確。

web。在web.config中配置

< service name="X.Y.Z.ContentService" behaviorConfiguration="XServiceBehavior"> 

SVC文件

<%@ ServiceHost Language="C#" Debug="true" Service="X.Y.A.ContentService" %> 

從上面可以看出,服務標記了名稱空間X.Y.Z其中SVC文件有X.Y.A.

(感謝馬克)

2

以前漂亮〜設置工作WCF停止工作,並顯示 - 錯誤 - 元數據發佈該服務目前被禁用。

雖然MEX設置是完美的,仍然WCF顯示上面的錯誤,原因是:從VS IDE中創建虛擬目錄沒有創建,但它給了「成功」的短信..

只需手動在IIS中創建虛擬目錄,賓果錯誤已解決。

希望它有幫助!

0

我有另一個問題。我有一個IIS asmx應用程序,並在裏面我已經放置了一個與svc子文件夾。配置得當,但它並沒有給我的元數據,直到我發現這個在web.config中的目錄:

<system.web> 
    <webServices> 
    <soapExtensionTypes> 
     <add type="SPFWebService.SPFWebServiceExtension,App_Code" priority="1" group="0" /> 
    </soapExtensionTypes> 
    </webServices> 
</system.web> 

通過刪除我的新服務,以一個單獨的目錄固定它。

0

如果你有一個沒有默認構造函數的類另一個構造函數,然後添加一個空的默認構造函數,我有同樣的問題,我解決了這個問題。

0

我有一個類似的問題。對於任何可能會在稍後遇到此問題的人。我的問題是,我的服務接口不具備[的ServiceContract] DataAnnotation

[ServiceContract] //<--This was missing 
public interface IServiceInterface 
{ 
    [OperationContract] 
    void Foo(Bar bar) 
    //... 
} 
相關問題