110,534
社区成员
发帖
与我相关
我的任务
分享
namespace Hosting
{
class Program
{
static void Main(string[] args)
{
Uri baseAddress = new Uri("http://localhost:8000/MyService");//创建一个URI对象,用来保存服务的基址(监听地址)
ServiceHost selfHost = new ServiceHost(typeof(MyService), baseAddress); //创建一个ServiceHost对象。
try
{
selfHost.AddServiceEndpoint(typeof(IService),new WSHttpBinding(),"MyService"); //将服务终结点添加到承载服务中
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();//启用元数据交换
smb.HttpGetEnabled = true;
selfHost.Description.Behaviors.Add(smb); //添加服务描述
selfHost.Open();//⑤启动服务
Console.WriteLine("服务已准备就绪");
Console.WriteLine("按下回车键以终止服务");
Console.WriteLine();
Console.ReadLine();
selfHost.Close();//关闭ServiceHostBase以关闭服务
}
catch (CommunicationException ce)
{
Console.WriteLine("异常:{0}", ce.Message);
selfHost.Abort();
}
}
}
}
那现在不需要这个Hosting项目了,我添加了一个ASP.NET 空web应用程序,这样行吗。那上面这些代码又放在哪里呢?我没有做过网站,我是做C/S的。