WCF TCP error


when I ran my first WCF application, I got the following error.
I have no idea what this means..I found that the last endpoint is giving this error.
can anybody let me know how to fix this issue?

System.ServiceModel.CommunicationException: A TCP error (10013: An attempt was made to access a socket in a way forbidden by its access permissions) occurred while listening on IP Endpoint= ---> System.Net.Sockets.SocketException: An attempt was made to access a socket in a way forbidden by its access permissions
   at System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress)
   at System.Net.Sockets.Socket.Bind(EndPoint localEP)
   at System.ServiceModel.Channels.SocketConnectionListener.Listen()
   --- End of inner exception stack trace ---
   at System.ServiceModel.Channels.SocketConnectionListener.Listen()
   at System.ServiceModel.Channels.BufferedConnectionListener.Listen()
   at System.ServiceModel.Channels.ConnectionAcceptor.StartAccepting()
   at System.ServiceModel.Channels.ConnectionDemuxer.StartDemuxing(Action`1 viaDelegate)
   at System.ServiceModel.Channels.ConnectionDemuxer.StartDemuxing()
   at System.ServiceModel.Channels.ExclusiveTcpTransportManager.OnOpen()
   at System.ServiceModel.Channels.TransportManager.Open(TransportChannelListener channelListener)
   at System.ServiceModel.Channels.TransportManagerContainer.Open(SelectTransportManagersCallback selectTransportManagerCallback)
   at System.ServiceModel.Channels.TransportChannelListener.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.ConnectionOrientedTransportChannelListener.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.TcpChannelListener`2.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open()
   at Microsoft.Tools.SvcHost.ServiceHostHelper.OpenService(ServiceInfo info)
System.Net.Sockets.SocketException (0x80004005): An attempt was made to access a socket in a way forbidden by its access permissions
   at System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress)
   at System.Net.Sockets.Socket.Bind(EndPoint localEP)
   at System.ServiceModel.Channels.SocketConnectionListener.Listen()

Now here is my code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.Threading.Tasks;

namespace HelloWorldService
    public class Name
        public string First;
        public string Last;

    public interface IHelloWorld
        string SayHello(Name Person);
    public class HelloWorldService: IHelloWorld
        public string SayHello(Name Person)
            return string.Format("Hello {0} {1}",
                Person.First, Person.Last);

Open in new window

And here is my App.config file
<?xml version="1.0" encoding="utf-8" ?>

    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
    <compilation debug="true" />
  <!-- When deploying the service library project, the content of the config file must be added to the host's 
  app.config file. System.Configuration does not support config files for libraries. -->
      <service name="HelloWorldService.HelloWorldService">
            <add baseAddress = "http://localhost:8080/helloworld" />
        <!-- Service Endpoints -->
        <!-- Unless fully qualified, address is relative to base address supplied above -->
        <endpoint address="ws" 
        <endpoint address="basic" 
         <endpoint address="net.tcp://localhost:8080/helloworld" 
        <!-- Metadata Endpoints -->
        <!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. --> 
        <!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
          <!-- To avoid disclosing metadata information, 
          set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="True" httpsGetEnabled="True"/>
          <!-- To receive exception details in faults for debugging purposes, 
          set the value below to true.  Set to false before deployment 
          to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="False" />


Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

10013 means either that port is blocked by your firewall, or another app is bound to it.  Can you please check your firewall settings then run netstat -a from a command prompt to see if anything else is bound?
IzzyTwinklyAuthor Commented:
Hi mrwad99,

Thank you so much.
However, it still gives me the same error even after I followed what you said.
00000.JPGI checked netstat -a after this setup. I couldn't found anything bound to 10013 nor 8080.00000.JPG
Hmm, OK:


a) changing the port to something else other than 8080,

b) changing app.config to use 127.0.01 instead of localhost, or even your actual IP address.  Your stacktrace shows it is trying to bind to - now means "all interfaces" so where it is getting from I don't know...
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

IzzyTwinklyAuthor Commented:
Hi mrwad99,

I finally figured it out, but still don't understand.
As soon as I used the different port numbers between '<add baseAddress = "http://localhost:8080/helloworld" />' and '<endpoint address="net.tcp://localhost:8081/helloworld" ', it worked.
Do you know anything about this?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
I'm very sorry but I cannot explain this; I'm not an expert on WCF but I do know a fair bit about TCP which is why I commented.  I'm glad you have it working though :)
IzzyTwinklyAuthor Commented:
no no..nothing to be sorry about. I found the answer because of you. you should get partial credit..thanks!!
Thank you Izzy, good luck in your future projects :)
IzzyTwinklyAuthor Commented:
mine worked
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.