00001 using System; 00002 using System.Collections.Generic; 00003 using System.Linq; 00004 using System.Text; 00005 using System.ServiceModel; 00006 using System.ServiceModel.Description; 00007 00008 namespace UtmConvert { 00009 class HttpService { 00010 ServiceHost selfHost; 00011 string _status = "ok"; 00012 00013 public HttpService(string uri, string address) { 00014 Uri baseAddress = new Uri(uri); 00015 selfHost = new ServiceHost(typeof(UtmConvertService), baseAddress); 00016 00017 try { 00018 selfHost.AddServiceEndpoint(typeof(IUtmConvertService), 00019 new WSHttpBinding(), address); 00020 ServiceMetadataBehavior smb = new ServiceMetadataBehavior(); 00021 smb.HttpGetEnabled = true; 00022 selfHost.Description.Behaviors.Add(smb); 00023 selfHost.Open(); 00024 } catch (CommunicationException ce) { 00025 _status = ce.Message; 00026 selfHost.Abort(); 00027 } 00028 } 00029 00030 ~HttpService() { 00031 selfHost.Close(); 00032 } 00033 00034 public HttpService() { 00035 Uri baseAddress = new Uri("http://localhost:8000/UtmConvert/UtmConvertService"); 00036 selfHost = new ServiceHost(typeof(UtmConvertService), baseAddress); 00037 00038 try { 00039 selfHost.AddServiceEndpoint(typeof(IUtmConvertService), 00040 new WSHttpBinding(), "UtmConvertService"); 00041 ServiceMetadataBehavior smb = new ServiceMetadataBehavior(); 00042 smb.HttpGetEnabled = true; 00043 selfHost.Description.Behaviors.Add(smb); 00044 selfHost.Open(); 00045 } catch (CommunicationException ce) { 00046 _status = ce.Message; 00047 selfHost.Abort(); 00048 } 00049 00050 } 00051 } 00052 }