C# Webservice WebException:无法连接到IIS中的远程服务器
当我想连接到某个主机时,我遇到了一些问题 我构建了一个web服务,从android智能手机获取图片。在安卓系统中,我安装了IP网络摄像头,使安卓智能手机成为IP摄像头。为了从android获取图片,我开发了web服务,根据android URL获取图片 当我在本地测试webservice时,它工作了。但是当我在IIS服务器中部署web服务时,web服务出现了问题。无法连接到远程服务器 这是个例外C# Webservice WebException:无法连接到IIS中的远程服务器,c#,web-services,iis,.net-4.0,system.net.webexception,C#,Web Services,Iis,.net 4.0,System.net.webexception,当我想连接到某个主机时,我遇到了一些问题 我构建了一个web服务,从android智能手机获取图片。在安卓系统中,我安装了IP网络摄像头,使安卓智能手机成为IP摄像头。为了从android获取图片,我开发了web服务,根据android URL获取图片 当我在本地测试webservice时,它工作了。但是当我在IIS服务器中部署web服务时,web服务出现了问题。无法连接到远程服务器 这是个例外 System.Net.WebException: Unable to connect to the
System.Net.WebException: Unable to connect to the remote server
---> System.Net.Sockets.SocketException: 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
172.21.2.1:8080
at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot,
SocketAddress socketAddress)
at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure,
Socket s4, Socket s6, Socket& socket, IPAddress& address,
ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout,
Exception& exception)
--- End of inner exception stack trace ---
at System.Net.HttpWebRequest.GetResponse()
at PhotoScanFromAndroid.ImageProcess.SavePhoto()
in D:\Project\PhotoScanFromAndroid\PhotoScanFromAndroid\ImageProcess.cs:line 45
这是从Android获取图片的功能:
public int SavePhoto()
{
try
{
String url = ConfigurationManager.AppSettings["CameraURL"];
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
// execute the request
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
// we will read data via the response stream
Stream ReceiveStream = response.GetResponseStream();
byte[] buffer = new byte[5000000];
//FileStream outFile = new FileStream(filename, FileMode.Create);
using (BinaryReader br = new BinaryReader(ReceiveStream))
{
buffer = br.ReadBytes(5000000);
br.Close();
}
return this.SavePhotoLinq(buffer).id_photo;
}
catch (Exception e)
{
//Assembly SampleAssembly;
TextWriter tw = new StreamWriter(getPath(), true);
tw.WriteLine(DateTime.UtcNow);
tw.WriteLine(e.ToString());
tw.WriteLine();
tw.Close();
return -1;
}
}
这是web.config
如果它表明您无法连接到服务器,这意味着什么?您无法连接到服务器。你先检查过了吗?连接、权限、防火墙等。请尝试从您的Web服务计算机ping和访问。用于调查web请求。在
response.GetResponseStream()处添加调试断点代码>