2012-09-07 276 views
0

使用外部用户服务时,发生以下错误。无法连接到远程服务器

无法连接到远程服务器

谁能能解释一下是哪里错了?有关使用外部Web服务的详细解释会有所帮助。

下面是我的一些代码:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using System.Runtime.Serialization; 
using System.Net; 
using System.IO; 

namespace sample_app 
{ 
    public partial class _Default : System.Web.UI.Page 
    { 
     protected void Page_Load(object sender, EventArgs e) 
     { 

     } 

     protected void Button1_Click(object sender, EventArgs e) 
     { 
      WebClient proxy = new WebClient(); 
      byte[] abc = proxy.DownloadData((new Uri("http://www.webservicex.net/WS/CATs.aspx?CATID=12&DESC=Utilities"))); 
      Stream strm = new MemoryStream(abc); 
+0

您是否更改了代码中实际实际URL的URL? –

+0

嗨菲利普!网址与每个代码相同。 – suraj

+0

啊,对不起,我认为这只是一个示例网址,现在我看到它的工作。 –

回答

0

尝试byte[] abc = proxy.DownloadData("http://www.webservicex.net/WS/CATs.aspx?CATID=12&DESC=Utilities");

WebClient.DownloadData方法应采取一个字符串作为paremeter,所以也许它只是不解释Uri类呢?

+0

嗨!!!!!感谢Deanna编辑这个问题。亲爱的菲利普我试着删除所有的行,但首先两个代码(即通过删除行流)仍然不工作 – suraj

+0

然后我不知道什么是错的,代码看起来很好。你确定你的防火墙不会阻止连接吗? –

相关问题