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

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

程序员文章站 2022-07-05 08:57:47
using System; using System.Diagnostics; using System.Linq; using System.ServiceModel; using System.ServiceModel.Channels; using System.ServiceModel.De... ......
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() { } } }