Web service in DW.mx

<script type="text/javascript"> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
<script type="text/javascript"> </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
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 Def inition Language) file along with it.  This gives applications want ing to use it some meta-data concern ing the service such as what are the method names, how many parameters it takes, and other useful tidbits of information.  By feed ing 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 call ing the Web service over the internet.  Beh ind the scenes, this is done with the WSDL command l ine utility that is installed with the .Net SDK.
The first step in consum ing a Web service involves f ind ing a Web service to consume.  Several Web sites exists solely for this reason: Sal Central XMethods Microsoft UDDI
Once you have found one you are interested in consum ing, f ind the l ink the WSDL file.  For this tutorial, we will be consum ing the GEO Cash ATM Lookup Web service.  With this service, we can f ind ATM locations in any US city by enter ing in a zip code.
Once you have found the service you wish to consume, you can create the proxy class for it by go ing to the Application panel and choos ing the Components tab.

When you click on the + icon, choose Add using WSDL.  This will br ing up the follow ing 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.  Beg in by creat ing 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  Enter code view and change the open ing form tag to look like this:
    <form runat="server"> From the ASP.Net Object panel, insert a TextBox with the ID of zip. Next, insert an ASP.Net button with the id of submit After adding the button id, go the Event > OnClick option in the tag editor and add the text "submit_click" 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.

    <script type="text/javascript"> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
    <script type="text/javascript"> </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值