您的位置:首页 > 其它

不通过配置文件启动WCF服务

2009-09-24 08:27 746 查看
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.ServiceModel;
using System.ServiceModel.Description;

namespace WCF1
{
[ServiceContract(Name = "MyService", Namespace = "http://www.huisoftware.com")]
public class MyService
{
[OperationContract]
public string MyMethod(string str)
{
return str + "Server Hello World";
}
}
class Program
{
static void Main(string[] args)
{
using (ServiceHost host = new ServiceHost(typeof(MyService)))
{
host.AddServiceEndpoint(typeof(MyService), new WSHttpBinding(), "http://127.0.0.1:8080/MyService");
if (host.Description.Behaviors.Find<ServiceMetadataBehavior>() == null)
{
ServiceMetadataBehavior behavior = new ServiceMetadataBehavior();
behavior.HttpGetEnabled = true;
behavior.HttpGetUrl = new Uri("http://127.0.0.1:8080/MyService/metadata");
host.Description.Behaviors.Add(behavior);
}
host.Opened += delegate
{
Console.WriteLine("WCF服务已经启动");
};
host.Open();
Console.Read();
}
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: