文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>WCF>一个服务器一个终结点一个客户端

WCF>一个服务器一个终结点一个客户端

时间:2010-10-12  来源:草珊瑚

服务器,服务契约,契约实现,服务器终结点。

客户端,客户端代理,客户端终结点。

 

 

建立服务契约,契约实现。

引用System.ServiceModel命名空间, 服务契约命名空间,操作契约。

代码 using System;
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;
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();
            }
        }
    }
}


 

 

相关阅读 更多 +
排行榜 更多 +
别惹神枪手安卓版

别惹神枪手安卓版

冒险解谜 下载
坦克战争世界

坦克战争世界

模拟经营 下载
丛林反击战

丛林反击战

飞行射击 下载