2014-03-30 77 views
0

我是WCF新手,現在正在使用「學習WCF:實踐指南」一書。本書使用VS2008作爲例子,我不確定使用什麼Visual Studio IDE作爲例子。我嘗試使用VS Express的網絡,它提供了以下錯誤:學習WCF - Visual Studio IDE

"HelloIndigo.exe does not contain static Main method suitable at entry point'.

我能理解這個問題的原因,但我不知道在哪裏添加的主要方法。所以我使用了VS Express for Desktop,並且它運行良好,但是由於我在第一章中繼續討論,我無法繼續,因爲VS Express for Desktop版本中沒有WCF服務模板。 VS2012僅在試用版中免費提供,並在90天內過期。那麼我應該使用哪種IDE?如果答案是VS Express for Web,那麼如何解決第一章中的示例錯誤? 書中提供的例子是 主持人:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using System.ServiceModel; 

namespace Host 
{ 
class Program 
{ 
    static void Main(string[] args) 
    { 
     using (ServiceHost host = new ServiceHost(typeof(HelloIndigo.HelloIndigoService),new Uri("http://localhost:8000/HelloIndigo"))) 
     { 
      host.AddServiceEndpoint(typeof(HelloIndigo.IHelloIndigoService), new BasicHttpBinding(), "HelloIndigoService"); 
      host.Open(); 

      Console.WriteLine("Please <ENTER> to terminate the service host"); 
      Console.ReadLine(); 
     } 
    } 
} 
} 

HelloIndigo:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using System.ServiceModel; 

namespace HelloIndigo 
{ 
public class HelloIndigoService : IHelloIndigoService 
{ 
    public string HelloIndigo() 
    { 
     return "Hello Indigo"; 
    } 
} 
[ServiceContract(Namespace="http://www.thatindigogirl.com/samples/2006/06")] 
public interface IHelloIndigoService 
{ 
    [OperationContract] 
    string HelloIndigo(); 
} 

}

客戶: Program.cs的

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using System.ServiceModel; 

namespace Client 
{ 
class Program 
{ 
    static void Main(string[] args) 
    { 
     EndpointAddress ep = new EndpointAddress("http://localhost:8000/HelloIndigo/HelloIndigoService"); 
     IHelloIndigoService proxy = ChannelFactory<IHelloIndigoService>.CreateChannel(new BasicHttpBinding(), ep); 
     string s = proxy.HelloIndigo(); 
     Console.WriteLine(s); 
     Console.WriteLine("Please <ENTER> to terminate client"); 
     Console.ReadLine(); 
    } 
} 
} 

ServiceProxy.cs:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using System.ServiceModel; 

namespace Client 
{ 
class ServiceProxy 
{ 
} 
[ServiceContract(Namespace = "http://www.thatindigogirl.com/samples/2006/06")] 
public interface IHelloIndigoService 
{ 
    [OperationContract] 
    string HelloIndigo(); 
} 

} 
+0

你可以發表一些代碼,所以我們可以看看?所有程序都需要一個主要方法。所以如果你沒有一個,那麼你將無法調試你正在編寫的應用程序,因爲它不能自行啓動。 – JNYRanger

+0

[無法在Visual Studio Express中使用WCF模板]的可能重複(http://stackoverflow.com/questions/10795522/cant-use-wcf-templates-in-visual-studio-express) –

回答

1

HelloIndigo應該編譯爲庫(DLL)而不是可執行文件。所以不應該有Main方法 - 它沒有一個作爲類庫。

Host的要點在於它將託管服務庫HelloIndigo並開始監聽該特定服務的端點上的調用。

更改HelloIndigo以編譯爲類庫並在Host中添加對HelloIndigo的引用。然後啓動Host過程。