| | | 用.NET创建Web Service客户端 | | 2001-09-27·
·crytal编译··yesky
| 上一页 1 2 3 4 5 6 7 8 下一页 客户端为windows应用程序
用Visual Studio.NET为Web Service创建一个Windows应用程序客户端也非常容易,按照一下步骤即可:
1)打开New Project窗口,在Project Type栏选择Visual C#,在Templates框中选择Windows Application
2)右击References,在弹出的菜单中点击Add Reference
3)点击.NET References"添加 "System.Web.Services.dll,引入控制台和Web 客户服务是一个好的编程习惯。
4)点击"Project",把LiveQuotes.dll作为一个引用加入工程。
5)现在该为应用程序创建窗体了,从左面的工具箱中拖放控件(如:标签,按钮等),visual studio.NET将在后台自动生成c#代码。我们仅仅需要输入处理用户事件的代码即可。
(完整的代码见附录2)
protected void btn_GetQuote_Click (object sender, System.EventArgs e) { LiveQuotes windowsClient = new LiveQuotes(); try { label_PriceValue.Text = windowsClient.MSNGetLastQuote (txt_CompanyCode.Text).ToString(); label_Name.Text = windowsClient.MSNGetCompanyName (txt_CompanyCode.Text).ToString(); } catch { label_PriceValue.Text = "0.0"; label_Name.Text = "The Company data is not available"; } }
protected void btn_Reset_Click (object sender, System.EventArgs e) { txt_CompanyCode.Text = ""; label_Name.Text = ""; label_PriceValue.Text = ""; } | 6)编译、执行客户端程序( visual studio.NET 的Debug -> Start )
7)验证一下,输入公司代码,你将得到公司名和来自NASDAQ的股票价格
这段程序代码创建了一个代理对象,利用SOAP通过HTTP调用远程对象的函数调用,使用try..catch捕获非法的公司代码,并使应用程序转入错误处理。
上一页 1 2 3 4 5 6 7 8 下一页 | | | 感谢
访问天极网,如果您觉得该文章涉及版权问题,请看这里!
|
|