【发布时间】:2023-03-15 01:48:01
【问题描述】:
我有一个带有 IIS 7.5 和一个 IP 的 Windows 2008 服务器。根目录下有两个Application,/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 不可公开访问。
我应该进行什么配置才能使这样的自引用调用起作用?
【问题讨论】:
-
为什么使用
WebRequest来使用 WCF 服务而不是强类型客户端代理? -
您可以在客户端应用与在服务器上相同的绑定配置,并使用强类型代理来使用它,并将序列化内容留给基础设施。无论如何,这实际上是题外话,在这种情况下,这不是导致您出现问题的原因。
-
我不知道有人能做到这一点!
-
是否可以从服务器本身访问 10.243.6.43:80 浏览器?
-
是的。我在上面提到过。
标签: c# asp.net-mvc wcf iis-7.5 asp.net-mvc-4