title: A request to send or receive data was disallowed because the socket is not connected
body: <p>I am trying to connect to a remote external server using TCP sockets in WCF code 
  My WCF service is the client which has code using sockets to connect to an external server.
  This code sends a request to an external server and receives the server response</p>
  
  <pre><code>int byteCount = 0;
          Socket m_socClient;
          try
          {
  
              string query = "My Request String";
              m_socClient = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
              System.Net.IPAddress remoteIPAddress = System.Net.IPAddress.Parse("127:0:0:0");
              System.Net.IPEndPoint remoteEndPoint = new System.Net.IPEndPoint(remoteIPAddress, 1234);
              EVCommon.Log("COnnecting to" + IPSelected + Port);
              m_socClient.Connect(remoteEndPoint);
              try
              {
              if (m_socClient.Connected)
              {
                  EVCommon.Log("Connected to" + IPSelected + Port);   
                  var reQuestToSend = string.Format("POST /ZZZZZ HTTP/1.1\r\nContent-Length:{0}\r\n\r\n{1}", query.Length, query);
                  byte[] bytesToSend = Encoding.ASCII.GetBytes(reQuestToSend);
                  byteCount = m_socClient.Send(bytesToSend, SocketFlags.None);
                  byte[] bytesReceived = new byte[1024];
                  byteCount = m_socClient.Receive(bytesReceived, SocketFlags.None);
                  Response271 = Encoding.ASCII.GetString(bytesReceived);
                  m_socClient.Disconnect(false);
                  m_socClient.Close(5000);
              }
              }
              catch(Exception ex)
              {
                  EVCommon.Log(ex.Message);
  
              }
  
  
          }
  </code></pre>
  
  <p>If I make a windows application with the same client code to connect to the remote server, it is successful. I am able to connect, send and receive
  This error occurs only when I bring WCF into the picture. The code fails at if(m_socket.Connected). So it is not able to connect successfully. </p>
  
  <pre><code>A request to send or receive data was disallowed because the socket 
  is not connected and (when sending on a datagram socket using a sendto call) no address was supplied. 
  </code></pre>
  
  <p>Thank you</p>