2013-07-30 74 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服務的應用程序池的身份運行的身份運行。

什麼是可能發生的是,應用程序池運行作爲沒有打開一個端口正確的網絡服務。

嘗試將應用程序池的標識更改爲您的用戶以檢查是否存在問題。

相關問題