How to use a newly started WCF service ASAP -


in application have manually start executable. executable acts server , starts wcf service whole initialization process takes time. in client (that has created new process) have use wcf service asap.

so check every 100ms service has started calling ping() method of service. first call throws endpointnotfoundexception handle. second call throws communicationobjectfaultedexception. i've checked , after handle endpointnotfoundexception state of communicationobject use create client proxy opened. approach wrong , how should check whether service started?

update1: how start wcf service:

servicehost servicehost = new servicehost(typeof(testservice)); const string address = "net.pipe://localhost/testservice"; binding binding = new netnamedpipebinding(); binding.receivetimeout = timespan.maxvalue; servicehost.addserviceendpoint(typeof(itestservice), binding, address);  servicehost.open(); while (true) {     thread.sleep(100); } 

update2: how create proxy:

channelfactory<itestservice> channelfactory =         new channelfactory<itestservice>(new netnamedpipebinding(), "net.pipe://localhost/testservice"); _testserviceproxy = channelfactory.createchannel(); 

and how ping service:

private static bool isserviceavailable(itestservice serviceproxy) {     const int maxnumberoftries = 100;     const int timeout = 100;     bool isserviceavailable = false;     int numberoftries = 0;          {         thread.sleep(timeout);         try         {             serviceproxy.ping();             isserviceavailable = true;         }         catch (endpointnotfoundexception)         {}         numberoftries++;          if (numberoftries > maxnumberoftries)             break;     }     while (!isserviceavailable);      return isserviceavailable; } 

the problem due fact cannot reuse faulted proxy, should create new one.

private static bool isserviceavailable(channelfactory<itestservice> channelfactory) {     const int maxnumberoftries = 100;     const int timeout = 100;     bool isserviceavailable = false;     int numberoftries = 0;          {         thread.sleep(timeout);         try         {             using(var proxy = channelfactory.createchannel())                 proxy.ping();              isserviceavailable = true;         }         catch (endpointnotfoundexception)         {}         numberoftries++;          if (numberoftries > maxnumberoftries)             break;     }     while (!isserviceavailable);      return isserviceavailable; } 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -