簡體   English   中英

從同一服務器上的MVC調用WCF服務時出現SocketException

[英]SocketException when calling WCF service from MVC on same server

我有一台帶有IIS 7.5和一個IP的Windows 2008 Server。 根目錄下有兩個應用程序,/ web和/ service。 / web是MVC4應用程序,/ service是WCF 4.0服務。

當我從MVC使用服務時,我使用以下代碼:

// Create the web request  
HttpWebRequest request = WebRequest.Create(TripServiceUrl + id) as HttpWebRequest;

// Get response  
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
    // Get the response stream  
    StreamReader reader = new StreamReader(response.GetResponseStream());

    // Console application output  
    tripJson = reader.ReadToEnd();
} 

我得到以下SocketException:

[SocketException (0x274c): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 10.243.6.43:80]
System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) +273
System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception) +584

但是,我可以從服務器上的瀏覽器中看到10.243.6.43:80(內部地址),並成功調用了該服務。 該IP無法公開訪問。

我應該做些什么配置才能進行自引用呼叫?

這可能是環回問題(安全性問題)。 請參閱http://support.microsoft.com/kb/896861

總結一下:

在注冊表編輯器中,找到並單擊下面的注冊表項:HKEY_LOCAL_MACHINE \\ SYSTEM \\ CurrentControlSet \\ Control \\ Lsa用鼠標右鍵單擊Lsa,指向新建,然后單擊DWORD值。 鍵入DisableLoopbackCheck,然后按Enter。 用鼠標右鍵單擊DisableLoopbackCheck,然后單擊修改。 在“數值數據”框中,鍵入1,然后單擊“確定”。

不要遵循有關DisableStrictNameChecking的步驟。

您還會發現許多不執行此操作的原因(畢竟,您是禁用安全檢查),然后有很多人說這是使SharePoint正常運行的唯一方法。 無論如何,它將幫助您確定是否是問題所在。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM