WCF DEMO2 基于HTTP-GET的元数据交换及Configure()方法以及添加MEX终结点

using System;
using System.Diagnostics;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;

 class Program
    {
        static void Main(string[] args)
        {
            ServiceHost serviceHost = new ServiceHost(typeof(Service1),new Uri("http://localhost:8000/EssentialWCF"));
       //ServiceHost serviceHost = new ServiceHost(typeof(Service1)); ServiceMetadataBehavior behavior
= serviceHost.Description.Behaviors.Find<ServiceMetadataBehavior>(); if (behavior==null) { behavior = new ServiceMetadataBehavior(); behavior.HttpGetEnabled = true;
          //behavior.HttpGetUrl=new Uri("http://localhost:8000/EssentialWCF"); serviceHost.Description.Behaviors.Add(behavior);
         //serviceHost.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexHttpBinding(), "http://localhost:8002/Essential"); } serviceHost.Open(); Console.ReadLine(); } [ServiceContract]
public interface IService1 { [OperationContract] void DoWork(); } [ServiceContract] public interface IService2 { [OperationContract] void Do(); } public class Service1 : IService1, IService2 { public static void Configure(ServiceConfiguration config) { Uri httpAddress = new Uri("http://localhost:8002"); Binding binding = new WSHttpBinding(); config.AddServiceEndpoint(typeof(IService1), binding, "http://localhost:8003/a"); config.AddServiceEndpoint(typeof(IService2), binding, "http://localhost:8003/b"); } public void Do() { } public void DoWork() { } } }

 

posted on 2018-01-08 13:57  方辰  阅读(297)  评论(1编辑  收藏  举报

导航