Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I can't see from your question how you are adding the correct endpoint, but I suspect you are attempting to modify the endpoint address. With WCF services, you cannot make changes to the endpoint address after calling </p> <pre><code>host.Open(); </code></pre> <p>because at this point the service is (if you have no errors) up and accepting requests from clients at the specified address and port number.</p> <p>You need to create a new ServiceHost object with the correct endpoint address (and dispose of the old one) if you wish to host the service at a new address.</p> <p>EDIT:</p> <p>After playing around with the example solution you have posted, I have found a solution to the issue. I think something is going wrong because you are using the same port number for both tries (in the example solution I downloaded you don't specify this, so the port defaulted to 808). The error you are experiencing vanishes if you change your code as follows to specify a different port number in the base address for the 2nd try:</p> <pre><code> try { var host2 = CreateServiceHost("localhost:5432", serviceImpl); Console.WriteLine("#2, config: " + host2.BaseAddresses.First().ToString()); host2.Open(); } catch (Exception ex) { Console.WriteLine(ex.Message); } </code></pre> <p>There seems to be something buggy underneath WCF itself, probably on a socket level, where the port is somehow still unavailable after the first error with the incorrect IP. </p> <p>I did a quick google and <a href="http://bytes.com/topic/c-sharp/answers/734497-closing-c-socket-does-not-release-port" rel="nofollow">found this article</a> where someone experienced a delay in reusing a port after closing a socket. If you always need to use the same port number, perhaps you could wait a certain amount of time for the port to become free again before trying to create the service host again.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload