2012-09-07 278 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

然後我不知道什麼是錯的,代碼看起來很好。你確定你的防火牆不會阻止連接嗎? –

相關問題