WCF>一个服务器一个终结点一个客户端
时间:2010-10-12 来源:草珊瑚
服务器,服务契约,契约实现,服务器终结点。
客户端,客户端代理,客户端终结点。
建立服务契约,契约实现。
引用System.ServiceModel命名空间, 服务契约命名空间,操作契约。

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
namespace HelloIndigo
{
[ServiceContract(Namespace="http://www.thatindigogirl.com/samples/2006/06")]
public interface IHeloIndigoService
{
[OperationContract]
string HelloIndigo();
}
public class HelloIndigoService:IHeloIndigoService
{
public string HelloIndigo()
{
return "Hello Indigo";
}
}
}
建立服务器,服务器终结点
服务器包括,契约实现的类,调用地址和方式。
服务器终结点包括,实现服务契约的类,调用方式,契约实现的名字。

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
namespace Host
{
class Program
{
static void Main(string[] args)
{
using (ServiceHost host = new ServiceHost(typeof(HelloIndigo.HelloIndigoService), new Uri("net.tcp://localhost:8000/HelloIndigo")))
{
host.AddServiceEndpoint(typeof(HelloIndigo.IHeloIndigoService), new NetTcpBinding(), "HelloIndigoService");
host.Open();
Console.WriteLine("Press <Enter> to terminate the service host");
Console.ReadLine();
}
}
}
}
相关阅读 更多 +