Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Web services 如何使用外部(免费或付费)web服务_Web Services - Fatal编程技术网

Web services 如何使用外部(免费或付费)web服务

Web services 如何使用外部(免费或付费)web服务,web-services,Web Services,如何在应用程序中使用外部web服务(付费或免费)。 例如: 下面是一个网站的代码片段(http://debugmode.net/2010/09/10/consuming-wcf-rest-service-in-asp-net-web-site/)它正在使用自创服务。但是,如果必须使用外部服务,应该如何进行 public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sende

如何在应用程序中使用外部web服务(付费或免费)。 例如: 下面是一个网站的代码片段(http://debugmode.net/2010/09/10/consuming-wcf-rest-service-in-asp-net-web-site/)它正在使用自创服务。但是,如果必须使用外部服务,应该如何进行

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://localhost:4567/Service1.svc/GetData"))); 
 Stream strm = new MemoryStream(abc);   
 DataContractSerializer obj = new DataContractSerializer(typeof(string));  
 string result = obj.ReadObject(strm).ToString();     
 TextBox1.Text = result; 
}

您应该将WebClient和流包含在using语句中,因为它们实现IDisposable,并且您希望调用它们的实现Dispose()方法。欢迎来到堆栈溢出!请阅读常见问题解答,以便获得更高质量的问题答案。您并不是指希望使用哪种语言访问Web服务(我猜是C#?)。请用语言重新标记你的问题。谢谢