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


    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();
                }
            }
        }
    }
  • 相关阅读:
    jquery-scrollstop
    Grunt usemin
    HTML5 之文件操作(file)
    启动mongodb bat
    判断是否支持WebP
    前端攻略系列(一)
    impress.js初体验
    JS应用实例3:定时弹出广告
    JS应用实例2:轮播图
    JS应用实例1:注册页面表单校验
  • 原文地址:https://www.cnblogs.com/liulun/p/1573014.html
Copyright © 2020-2023  润新知