从同一服务器上的MVC调用WCF服务时出现SocketException

Bil*_*mpf 8 c# asp.net-mvc wcf iis-7.5 asp.net-mvc-4

我有一台带有IIS 7.5和一个IP的Windows 2008 Server.根,/ web和/ service下有两个Application./ 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();
} 
Run Code Online (Sandbox Code Playgroud)

我得到以下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
Run Code Online (Sandbox Code Playgroud)

但是,我可以从服务器上的浏览器看到10.243.6.43:80(内部地址)并成功调用该服务.知识产权不公开.

我应该做什么配置才能像那样工作进行自我参考调用?

Gre*_*ter 1

这可能是一个环回问题(安全问题)。请参阅http://support.microsoft.com/kb/896861

总结一下:

在注册表编辑器中,找到并单击以下注册表项: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa 右键单击​​ Lsa,指向新建,然后单击 DWORD 值。键入“DisableLoopbackCheck”,然后按 Enter。右键单击“DisableLoopbackCheck”,然后单击“修改”。在“值数据”框中,键入 1,然后单击“确定”。

不要执行有关DisableStrictNameChecking 的步骤。

您还会发现很多不这样做的理由(毕竟,您禁用了安全检查),然后很多人说这是让 SharePoint 正常工作的唯一方法。无论如何,它将帮助您确定这是否是问题所在。