C# 学习WCF-VisualStudioIDE
我是WCF新手,现在正在使用《学习WCF:动手指南》一书。这本书使用了VS2008作为示例,我不确定使用什么样的VisualStudioIDE作为示例。我尝试使用VS Express for Web,但出现以下错误: “HelloIndigo.exe不包含适用于入口点的静态主方法” 我可以理解问题的原因,但我不确定在哪里添加主要方法。因此,我使用了VS Express for Desktop,效果很好,但正如我在第一章中继续说的那样,我无法继续,因为VS Express for Desktop版本中没有WCF服务模板。VS2012仅在试用版中免费提供,并且过期90天后。那么我应该使用什么IDE呢?如果答案是VS Express for Web,那么如何修复第一章示例中的错误? 书中提供的例子是 主持人: } 客户: Program.csC# 学习WCF-VisualStudioIDE,c#,wcf,visual-studio,visual-studio-2012,C#,Wcf,Visual Studio,Visual Studio 2012,我是WCF新手,现在正在使用《学习WCF:动手指南》一书。这本书使用了VS2008作为示例,我不确定使用什么样的VisualStudioIDE作为示例。我尝试使用VS Express for Web,但出现以下错误: “HelloIndigo.exe不包含适用于入口点的静态主方法” 我可以理解问题的原因,但我不确定在哪里添加主要方法。因此,我使用了VS Express for Desktop,效果很好,但正如我在第一章中继续说的那样,我无法继续,因为VS Express for Desktop版
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();
}
}
}
HelloIndigo
应该编译为库(DLL),而不是可执行文件。因此不应该有Main
方法-它没有类库
Host
的要点是,它将托管服务库HelloIndigo
,并开始侦听对该特定服务的端点的调用
将
HelloIndigo
更改为编译为类库,并在Host
中添加对HelloIndigo
的引用。然后启动Host
进程。你能发布一些代码让我们看看吗?所有程序都需要一个主方法。因此,如果你没有主方法,那么你将无法调试正在编写的应用程序ng,因为它无法自行启动。可能重复
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();
}
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();
}
}
}
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();
}
}