2013-06-25 282 views
1

我真的很抱歉再次問這個問題。有類似的帖子,但沒有解決方案爲我工作。WCF服務無法啓動

我在VisualStudio2010中創建了一個新的WCF服務項目。它創建一個IService1.cs,Service1.svc和Service1.svc.cs

因此,當我嘗試調試/啓動服務時,出現以下錯誤。我正在運行Win7 x64。我正在使用集成的VisualStudio開發服務器(右鍵單擊項目 - >轉到頁面「Web」)。

類型「Projector.Service1」,作爲服務提供屬性值 在ServiceHost的指令,或者在配置元件 system.serviceModel/serviceHostingEnvironment/serviceActivations提供可以 不會被發現。

任何想法如何解決,而無需在IIS中運行它?

在此先感謝。

的Service1.svc只包含一個行:

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

的Service1.svc.cs包含一個自動生成的類:

namespace Projector 
{ 
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together. 
    public class Service1 : IService1 

下面是在Web.config

<?xml version="1.0"?> 
<configuration> 

    <system.web> 
    <compilation debug="true" targetFramework="4.0" /> 
    </system.web> 
    <system.serviceModel> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior> 
      <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment --> 
      <serviceMetadata httpGetEnabled="true"/> 
      <!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information --> 
      <serviceDebug includeExceptionDetailInFaults="false"/> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> 
    </system.serviceModel> 
<system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"/> 
    </system.webServer> 

</configuration> 
+0

你有沒有編譯錯誤? – CodeCaster

+0

沒有編譯錯誤。 – Matthias

+0

你可以發佈你的配置文件部分 ..嗎? – vendettamit

回答

2

AFAIK,如果你不使用IIS,svc是無用的。在IIS之外,所謂的自託管方法需要您編寫類似這樣的內容,其中HelloWorldWcfServiceMessage是實現服務合約的類型。另外,不要忘記爲服務器配置端點,並確保允許您在配置的端口上打開服務。您可以在Windows服務或控制檯程序中使用以下代碼(更適合測試和調試)。希望有所幫助,我的問題正確。

... 
this.serviceHost = new ServiceHost(typeof(HelloWorldWcfServiceMessage)); 
this.serviceHost.Open(); 
... 

public class HelloWorldWcfServiceMessage : IHelloWorldWcfServiceMessage 
{ 

} 

[ServiceContract(Namespace = "http://HelloWorldServiceNamespace", Name = "PublicHelloWorldWCFService")] 
public interface IHelloWorldWcfServiceMessage 
{ 
    [OperationContract] 
    string HelloWorldMessage(string name); 
} 
+0

我目前正在嘗試此解決方案。但是我想在ServiceHost的構造函數中設置一個自己的uri(帶端口的HTTP)作爲第二個參數,但是我得到一個異常,它已經包含一個HTTP地址。你將如何配置一個EndPoint? – Matthias

+0

修正了它。我必須更改App.config文件並在那裏刪除/修復EndPoint。 – Matthias

+0

好。 app.config是此配置的正確位置。 –

0

我覺得這個名字有些混亂。

在你寫的SVC中: CodeBehind =「Service1.svc.cs」 但是你說你的文件名是Service.svc.cs(不帶1)。

+0

不,對不起。寫這個問題時,這只是一個拼寫錯誤。實際的代碼是正確的。我解決了上面的問題。 – Matthias

0

解決了這個

這是所有關於IIS 8

所有學分發布WCF服務去捷爾吉Balássy

WCF服務,不要在IIS 8運行與默認配置,因爲Web服務器不知道,如何處理傳入的請求目標.svc文件。你可以分兩步教:

請在這裏查看相同的答案。

https://stackoverflow.com/a/45979587/3059688