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 00011 public delegate void updateErrorEventHandler(Exception error); 00012 public event updateErrorEventHandler updateErrorEvent; 00013 00014 ServiceHost selfHost; 00015 string _status = "ok"; 00016 00017 public HttpService(string uri, string address) { 00018 Uri baseAddress = new Uri(uri); 00019 selfHost = new ServiceHost(typeof(UtmConvertService), baseAddress); 00020 00021 try { 00022 selfHost.AddServiceEndpoint(typeof(IUtmConvertService), 00023 new WSHttpBinding(), address); 00024 ServiceMetadataBehavior smb = new ServiceMetadataBehavior(); 00025 smb.HttpGetEnabled = true; 00026 selfHost.Description.Behaviors.Add(smb); 00027 selfHost.Open(); 00028 } catch (CommunicationException ce) { 00029 if (updateErrorEvent != null) 00030 updateErrorEvent.Invoke(ce); 00031 _status = ce.Message; 00032 selfHost.Abort(); 00033 } 00034 } 00035 00036 ~HttpService() { 00037 selfHost.Close(); 00038 } 00039 00040 public HttpService() { 00041 Uri baseAddress = new Uri("http://localhost:8000/UtmConvert/UtmConvertService"); 00042 selfHost = new ServiceHost(typeof(UtmConvertService), baseAddress); 00043 00044 try { 00045 selfHost.AddServiceEndpoint(typeof(IUtmConvertService), 00046 new WSHttpBinding(), "UtmConvertService"); 00047 ServiceMetadataBehavior smb = new ServiceMetadataBehavior(); 00048 smb.HttpGetEnabled = true; 00049 selfHost.Description.Behaviors.Add(smb); 00050 selfHost.Open(); 00051 } catch (CommunicationException ce) { 00052 if (updateErrorEvent != null) 00053 updateErrorEvent.Invoke(ce); 00054 _status = ce.Message; 00055 selfHost.Abort(); 00056 } 00057 00058 } 00059 } 00060 }