2013-07-30 24 views
0

我试图连接到使用TCP套接字在WCF代码远程外部服务器 我的WCF服务是具有使用套接字连接代码到客户端外部服务器。 该代码发送到外部服务器的请求,并接收服务器响应发送或接收数据的请求被禁止,因为套接字未连接

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); 

      } 


     } 

如果我使用相同的客户端代码一个窗口应用程序连接到远程服务器,它是成功的。我能够连接,发送和接收 只有当我将WCF带入图片时才会出现此错误。 if(m_socket.Connected)代码失败。所以它无法成功连接。

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. 

谢谢

回答

0

不同的是,在Windows应用程序的登录用户和WCF服务的应用程序池的身份运行的身份运行。

什么是可能发生的是,应用程序池运行作为没有打开一个端口正确的网络服务。

尝试将应用程序池的标识更改为您的用户以检查是否存在问题。

相关问题