欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

WCF DEMO1 创建自托管宿主

程序员文章站 2022-07-05 08:46:49
using System; using System.ServiceModel; using System.ServiceModel.Channels; //注意:需要引用程序集 System.ServiceModel 并在管理员模式下运行 class Program { static void M... ......
using System;
using System.ServiceModel;
using System.ServiceModel.Channels;    
//注意:需要引用程序集 System.ServiceModel 并在管理员模式下运行
    class Program
    {
        static void Main(string[] args)
        {
            Uri httpAddress = new Uri("http://localhost:8002");
            ServiceHost serviceHost = new ServiceHost(typeof(Service1), httpAddress);
            Binding binding = new WSHttpBinding();
            serviceHost.AddServiceEndpoint(typeof(IService1), binding, "http://localhost:8002/a");
            serviceHost.AddServiceEndpoint(typeof(IService1), binding, "http://localhost:8002/b");
            serviceHost.Open();
            Console.ReadLine();
            serviceHost.Close();

        }
    }
    [ServiceContract]
    public interface IService1
    {
        [OperationContract]
        void DoWork();
    }
    [ServiceContract]
    public interface IService2
    {
        [OperationContract]
        void Do();
    }
    public class Service1 : IService1, IService2
    {
        public void Do()
        {

        }

        public void DoWork()
        {

        }
    }