Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 8th, 2012  |  syntax: None  |  size: 2.26 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. WCF Windows service with an API to a windows form client, API return value tells me it could not connect to device. Whats the preffered way?
  2. var serviceType = typeof(Mail2SmsServerApi);
  3.  
  4.             var uri = new Uri("http://localhost:8000/");
  5.             host = new ServiceHost(serviceType, new[] { uri });
  6.  
  7.             var behaviour = new ServiceMetadataBehavior() { HttpGetEnabled = true };
  8.             host.Description.Behaviors.Add(behaviour);
  9.  
  10.             host.AddServiceEndpoint(serviceType, new BasicHttpBinding(), "Hello");
  11.             host.AddServiceEndpoint(typeof(IMetadataExchange), new BasicHttpBinding(), "mex");
  12.  
  13.             host.Open();
  14.        
  15. [ServiceContract]
  16. public class Mail2SmsServerApi
  17. {
  18.     [OperationContract]
  19.     public string Imei()
  20.     {
  21.         try
  22.         {
  23.             GSMHandler gsm = new GSMHandler();
  24.             return gsm.GetImei();
  25.         }
  26.         catch (Exception ex)
  27.         {
  28.             LogText.Error("API GetImei(), exception: " + ex.ToString());
  29.             return null;
  30.         }
  31.     }
  32.        
  33. public bool OpenConnection()
  34.     {
  35.  
  36.         modem = new GsmPhone(_comport, _baudrate, _timeout);
  37.  
  38.         if (!comm.IsConnected())
  39.         {
  40.             try
  41.             {
  42.                 modem.Open();
  43.                 return true;
  44.             }
  45.             catch (Exception ex)
  46.             {
  47.                 LogText.Debug("OpenConnection(), exception" + ex.ToString());
  48.                 return false;
  49.             }
  50.         }
  51.         else
  52.         {
  53.             try
  54.             {
  55.                 modem.Close();
  56.                 modem.Open();
  57.                 return true;
  58.             }
  59.             catch (Exception ex)
  60.             {
  61.                 LogText.Debug("OpenConnection(), exception" + ex.ToString());
  62.                 return false;
  63.             }
  64.  
  65.         }
  66.     }
  67.     public string GetImei()
  68.     {
  69.         string imei = "";
  70.         try
  71.         {
  72.             imei = modem.RequestSerialNumber();
  73.             LogText.Debug("IMEI:" + _IMEI);
  74.             return imei;
  75.         }
  76.         catch (Exception ex)
  77.         {
  78.             LogText.Error("Error caught in GetImei(), exception: " + ex.ToString());
  79.             return imei;
  80.         }
  81.     }
  82.        
  83. gsm = new GSMHandler();
  84.                 gsm.OpenConnection();
  85.        
  86. gsm = new GSMHandler();
  87.                 gsm.OpenConnection();