我的一亩三分地 我就喜欢!
13fen  设为主页
 收藏本站
 
当前位置: > 一亩三分地:首页 > 网络编程 > net专区 > Web service in DW.mx
热门文章排行
热门文章排行 用VB.NET设计各种形状的窗体界面一(11-23)
NETFramework1.0精简版(12-22)
.Net中的反射使用入门(12-22)
C#多线程应用技术面对面探讨(11-23)
用C#.net轻松制作不规则窗体(12-15)
精采文章排行
精采文章排行 ASP.NET与MySQL数据库简明图示入门教(11-16)
ASP.NET与MySQL数据库简明图示入门教(11-16)
ASP.NET 链接数据库基础(11-16)
webconfig的设置节点说明(11-16)
部署ASP.NET的三大技术(上)(11-16)
技术专题推荐
网管论坛交流
 

Web service in DW.mx 

作者:   来源:   点击:   日期:2007-11-20

Consuming Web Services in ASP.Net


Web services have quickly become the most touted industry buzzword.  The fact that they are based on XML and other "Internet" standards make it the ideal vehicle to send and recieve information between applications.  Dreamweaver MX has taken this into consideration and given you the power to consume web services in a visual environment.
When a web service is published, it will also have a WSDL (Web Service Definition Language) file along with it.  This gives applications wanting to use it some meta-data concerning the service such as what are the method names, how many parameters it takes, and other useful tidbits of information.  By feeding Dreamweaver the URL of this WSDL file, you give it the information it needs to create what's called a proxy class.  This is a .Net assembly (.dll) that hides all of the intricate details involved in calling the web service over the internet.  Behind the scenes, this is done with the WSDL command line utility that is installed with the .Net SDK.
The first step in consuming a web service involves finding a web service to consume.  Several web sites exists solely for this reason:
Once you have found one you are interested in consuming, find the link the WSDL file.  For this tutorial, we will be consuming the GEO Cash ATM Lookup web service.  With this service, we can find ATM locations in any US city by entering in a zip code.
Once you have found the service you wish to consume, you can create the proxy class for it by going to the Application panel and choosing the Components tab.

When you click on the + icon, choose Add using WSDL.  This will bring up the following dialog.

Enter the WSDL URL and Dreamweaver will create two files in your site root, a .dll file which must be moved and uploaded to the /bin directory, and a .cs file with the source for the .dll in case you want to take a peek below the hood.  Another look at the Components panel will reveal a tree view of available methods in the .dll.

Once all of this is registered, you are ready to create your web form.  Begin by creating a new .aspx file either from File > New dialog, or right clicking in the site window and choosing New File.  
Create the web form by following these steps:
  1. Add a form from the Form object panel
  2. Enter code view and change the opening form tag to look like this:
    <form runat="server">
  3. From the ASP.Net Object panel, insert a TextBox with the ID of zip.
  4. Next, insert an ASP.Net button with the id of submit
  5. After adding the button id, go the Event > OnClick option in the tag editor and add the text "submit_click"
  6. Add a simple ASP.Net label with the id result

Once all of this has been done, your web form should look like this:

The final step, is to add the code that will process the GEOCash service.  Begin by adding this code to the top of the page.
<script language="C#" runat="server">
void submit_click(Object ob, EventArgs ev)
{

}
</script>
Once that is added, you can drag over the two lines from the Application > Components tab that say:
-GeoCash()
-String GetATMLocations(String)
The result will look like this.
<script language="C#" runat="server">
void submit_click(Object ob, EventArgs ev)
{
GeoCash aGeoCash = new GeoCash();
String aString = aGeoCash.GetATMLocations(/*String*/enter_value_here);
}
</script>
One more small modification, and you will have a working application.  Just make these small changes to the code.
  • Replace /*String*/enter_value_here with zip.Text
  • Add this line right before the closing }
    result.Text = Server.HtmlEncode(aString);

The result that comes from the web service is a chunk of XML in the form of a string.  For the purpose of this example, we just Html encoded it so you can see the xml tags in the browser (even though the formatting leaves a lot to be desired).  In a real world scenario, you would probably use the XmlDocument object to process the XML blob.  The final code for this example will look like this:
<script language="C#" runat="server">
void submit_click(Object ob, EventArgs ev)
{
GeoCash aGeoCash = new GeoCash();
String aString = aGeoCash.GetATMLocations(zip.Text);
result.Text = Server.HtmlEncode(aString);
}
</script>
The only thing that is left is to upload and test your application.  Remember to also upload the geocash.dll to your /bin directory.  Click here to see a working example of the form in this tutorial.


文章评论】 【收藏本文】 【推荐好友】 【打印本文】 【论坛讨论

   相关文章:
·Web service in DW.mx ·ASP.NET 链接数据库基础
·ASP.NET开发简明手册 ·Perl程序设计中常用的函数之四
·perl实例分析教程之六 ·CGI教学:第一章 cgilib例

   文章评论:(条)
  
 请留名: 匿名评论   点击查看所有评论 网管论坛
 

  责任编辑:一分  声明:刊登此文章是为了传递更多信息,文章内容仅供参考,转载请注明出处。