Tuesday, February 18, 2014

WCF Client : An existing connection was forcibly closed by remote host [My Fix]

After I made a few changes to my WCF service, I hosted it in the staging server (in another machine, another country!).

Everything was working fine in my local machine and I didn't really check the Web.Config for service references. 

Once I tried to login to my system, (by the way, I have enabled tracing and logging on both service and client), it gave me this error in the big yellow screen of death.

An existing connection was forcibly closed by remote host


It was a real headache and I searched through internet like crazy. I came across this answer... http://stackoverflow.com/a/12105703/959245

And started looking into my web.config file.

And I saw this...(highlighted)

 <system.serviceModel>
     ....
    <client> 
      <endpoint address="net.tcp://localhost:8009/LookupService" ...>
        <identity>
          <servicePrincipalName value="host/user-PC" />
        </identity>
      </endpoint> 
    </client>
    ....
  </system.serviceModel>
That is from my local development machine. That <identity> is for my local machine. In IIS server, there's no account called USER-PC

What I did was to remove the highlighted part and voila! It works!!!!

Identities can go a long way.... from security to headaches!