Webservice WebException:无法连接到IIS中的远程服务器

时间:2012-11-12 04:15:51

标签: c# web-services iis .net-4.0 system.net.webexception

当我想连接某个主机时,我遇到了一些问题。

我构建了一个Web服务来从Android智能手机获取图片。在android中,我已经安装了IP WebCam来制作Android智能手机作为ip camera。为了从android获取图片,我开发了web服务以根据android URL获取图片。

当我在本地测试web服务时,它工作。但是当我在IIS服务器中部署Web服务时,Web服务有问题。无法连接到远程服务器。

这是例外

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

<configuration>
    <appSettings>
        <add key="CameraURL" value="http://192.168.88.115:8080/photo.jpg"/>
    </appSettings>
</configuration>

0 个答案:

没有答案