Using FrontPage to use XML WebService

Source: Internet
Author: User
Tags command line html form http post iis interface web services microsoft frontpage visual studio
Frontpage|web|xml

XML Web Service

The most exciting thing about Microsoft's. NET Framework is the inclusion of Extensible Markup Language (XML) Web Service. WEB services allow you to communicate and exchange information in a standards-based manner between applications. The implementation of Microsoft's WEB services has many intrinsic benefits. Using Hypertext Transfer Protocol (HTTP) and Transmission Control Protocol (TCP/IP), you can exchange information in XML format (/internet). As a result, Web services use existing structures and can be easily implemented in existing environments.

In this article, we will use the Eightball Web service on the Microsoft GotDotNet Web site. We will create a Web page that will send a request to the Eightball Web service. The Eightball Web service will accept and process the request, and return a response that can be displayed on our web page. The process of using a Web service's response is the so-called "use" Web service.

Requirements for using WEB services

To use a WEB service, you must have several components. If you are using Microsoft Visual Studio?. NET, these components are automatically installed in the appropriate location. and in order to achieve the objectives of this article, we will adopt Microsoft FrontPage? Web site creation and management tools to use Web services.

To use FrontPage for WEB services, you need to have:

1 Microsoft. NET Framework Software Development Kit (SDK)

2 Microsoft Internet Information Services (WEB server built in Iis,windows server operating system)

3 Web Service Proxy

4 asp.net Web forms

Microsoft. NET Framework SDK

The Microsoft. NET Framework provides a programming model for the Microsoft. NET Platform. It allows us to create sophisticated Web services and applications. The. NET Framework allows you to create ASP.net pages that are required to use the Eightball Web service. To complete the steps described in this article, you need to have the. NET Framework SDK.

Microsoft Internet Information Services

We must have a Web server, and the Web server must support asp.net. You can use Microsoft Internet information Services on Windows 2000 or Windows XP. You may also need to install the necessary security updates.

If you install IIS after you install the. NET Framework SDK, you need to run the aspnet_regiis.exe in the. NET Framework directory to install asp.net support.

Web Service Proxy

A Simple Object Access Protocol (SOAP) message is used between the client and the WEB service to communicate. For more information, see the SOAP site. The WEB service Proxy is responsible for forming a SOAP message and sending the messages over the network. This makes it extremely easy to use WEB services because you do not need to map parameters to XML elements. The Web service proxy includes a dynamic link library (DLL) on the local Web server. Using the utility named WSDL.exe that is included with the. NET Framework SDK, you can generate source code files for Microsoft Visual Basic. NET or C #, and then use that file to compile the Web service proxy. This is very easy to implement and we will explain it in more detail later.

  asp.net Web forms

We need to provide users with a way to ask questions about Eightball services. We will use the ASP.net Web form for this purpose. Because FrontPage does not have the ability to generate ASP.net components in the user interface, we will generate WEB forms through manual encoding in HTML view.

Preparing for the use of WEB services

If you have already installed the Microsoft. NET Framework SDK and Internet information Services, we can immediately explore how to use the Eightball Web service. Here are the steps you need to take to use a WEB service:

1. Check the WEB service.

2. Generate source code files.

3. Compile the Web service proxy.

4. Design asp.net interface.

5. Connect Web Services.

6. Copy Agent.

7. Test the ASP.net application.

  Checking Web Services

To check the Web service and view the types of information it provides, we browse to the Web service entry point. The link for this particular Web service is http://www.gotdotnet.com/playground/services/EightBall/eightballws.asmx. If you browse to the URL, you will see a list of the actions that the WEB service supports. In this case, you'll see a link to the Ask action.

Figure 1: HTTP Post information for the Ask operation

If you click the link to the Ask action, you will see an instance of the SOAP request and the Web service response. If you examine the request and response, you will find that the ask operation requires that you pass a string to it (note the "psquestion=string" text in the HTTP POST segment) and return a string. This page includes a text box where you can type a question and receive an XML-formatted answer from the Eightball Web service.

You need to use this information to design the interface in FrontPage to use the Web service. By examining the Web service entry point, we conclude that we need to design a form where a text box is used to enter the problem, and there is a button to submit the problem to the Web service. You then need to provide a page element to contain the answers returned from the Web service. We will discuss it in depth later. Now we need to generate the source code to compile the Web service proxy class.

  Generate Source code files

The actual. NET assembly that is used for the Web service resides on the Web server on which the Web service is loaded. However, the proxy class for the client is responsible for creating a well-formed SOAP request for the Web service. Therefore, we need to create a. NET assembly that acts as a proxy class on the local WEB server. You can easily do this by using the tools provided in Microsoft's. NET Framework SDK.

To generate the source code files for the proxy class, we will use the Web Service Description Language utility, the WSDL.exe. You can find the utility in the directory where the. NET Framework SDK is installed. (By default, the utility will be installed in the C:\Program Files\Microsoft Visual Studio. Net\frameworksdk\bin folder.) WSDL.exe allows us to create source files for the proxy class.

Before you generate the source file, create a directory in the root directory of drive C for the Web service files. Name the directory 8Ball. Once the directory is created, we can build the files necessary to use the Eightball Web service.

To generate a source code file:

1. Click Start, point to Programs, point to Accessories, and click Command Prompt to open a command prompt window.

2. Go to the directory that contains the WSDL.exe utility.

3. Type the following on the command line, and then press ENTER:

Wsdl/l:vb/o:c:\8ball\8ball.vb

http://www.gotdotnet.com/playground/services/EightBall/eightballws.asmx?wsdl

Use the following switch in WSDL.exe to generate the source file:

/L-This switch specifies the language of the source file. In this example, we specify the Visual Basic language. You can also specify the CS (C #) language, which generates a C # source file.

/O-This switch specifies the name of the output file. The Visual Basic source file should have a. vb file name extension. C # source files should have a. cs file name extension.

Note: Use/? Switch to obtain detailed information about the WSDL.

The URL that is passed to the WSDL is the URL that points to the WEB service contract. A Web service contract is a document that lists the types of information that should be provided to the Web service and the type of information it will return. The URL of a Web service contract is to append the WSDL at the end of the Web service entry point URL.

Now we have successfully generated the Visual Basic. NET source code files that are used to compile the Web service proxy class.

  Compiling a WEB service proxy

After you create the Visual Basic. NET source file, we need to compile it into the Web service proxy. To do this, we'll use the Visual Basic. NET compiler that came with the. NET Framework SDK.

To compile the proxy class, at the Open command prompt, type:

Vbc/t:library/out:c:\8ball\8ballclient.dll

/r:system.dll/r:system.xml.dll/r:system.web.services.dll C:\8Ball\8Ball.vb

We use the following switches to generate the proxy class:

/T-This switch specifies the type of assembly to generate. In this case, we want to compile the DLL file, so we specify the assembly type as the library.

/out-This switch specifies the name of the output file. Because we specify the assembly type of the library, the output file name must have a. dll file extension.

/R-This switch specifies a reference to an assembly. In this case, we refer to three Microsoft. NET namespaces, all of which are required by all WEB service Proxy clients. They are the System, System.Xml, and System.Web.Services namespaces.

After the compiler finishes compiling the proxy class, a file named 8BallClient.dll is available in the 8Ball directory of drive C. This is the proxy client. We'll move it to the right place later. You can close the Command prompt window and we will continue to create an interface for interacting with the Eightball Web service.

  Design asp.net interface

Now that we have a general idea of the interface that needs to be created, the WEB service proxy class has been successfully compiled. The next step is to create a asp.net form that you can use to interact with the Eightball Web service.

Before you design the ASP.net interface, you need to create a FrontPage project. Create a new one-page Web site and name it 8Ball. It is important that you create the site on the WEB server where asp.net is installed.

After you create a 8Ball site, you need to be sure to mark it as the root of your application. The steps are as follows:

1. Click Start, point to Settings, and click Control Panel to open the Control Panel.

2. Double-click Administrative Tools.

3. Double-click Internet Services Manager (Windows 2000) or Internet Information Services (Windows XP Professional).

4. Expand the default Web site node to see the 8Ball site. (In Windows XP Professional, you need to expand the Web Sites node to find the default Web site node)

5. Right-click the 8Ball node and select Properties.

6. The Properties dialog box opens with the Contents tab displayed. If not, click the Contents tab.

7. In the Application Settings section, click the Create button to set the site as the root of the application.

8. Click OK.

The Web site is now the root of the application, and we can continue to create the ASP.net user interface.

Three asp.net Web forms controls will be used in the user interface. The TextBox control is used to enter a problem with the Eightball Web service, which is used to initialize requests for Web services, and the Label control is used to display answers received from Web services. All of these controls are included in the ASP.net form.

Using Microsoft Visual Studio. NET to design Web forms is easy, simply drag and drop the form elements and set the properties of those elements in the user interface. In this case, we are not using Visual Studio. NET, so we have to generate the form elements by hand encoding.

  Create a Web form

The first thing you need to do is create the code for the Web form itself. If you are familiar with the form code for Hypertext Markup Language (HTML), you must also be familiar with the code. Open the home page of the 8Ball site and switch to HTML view. Type the following code in the existing markup:

<form runat= "Server" ></form>

In addition to adding the Runat property, the code is exactly the same as an HTML form. The value of the Runat property is the server, which means that the form is a ASP.net server control. This is a perfect example of the simplicity of asp.net. To make an HTML element an ASP.net server control, simply add the Runat property and set its value to server.

At this point, you should save this page and continue with the following steps. Save the page as a 8ball.aspx.

  Add asp.net Web Forms control

After you create the form, you need to add the ASP.net Web forms control.

First, add a TextBox control. This is where the Web page user enters the Eightball Web service problem. To add a TextBox control, start and end

Add the following code between the tags:

<asp:textbox id= "tbquestion" runat= "Server"/> 

If you've never coded in asp.net, the code may be unfamiliar to you. ASP that is appended to the name of the control: This is an asp.net Web forms control

Add the rest of the code to the page, and the form code looks like this:

<form runat= "Server" >
<asp:textbox id= "tbquestion" runat= "Server"/>
<asp:button id= "Btngo" runat= "Server"
text= "Submit question"/><br><br>
<asp:label id= "Lblanswer" runat= "Server"/>
</form> <>  

You may notice that these controls are not visible in the normal view of FrontPage. This is exactly what you want, because these are asp.net Web forms controls that FrontPage cannot display.

  Connecting to Web Services

If you review the code that you have added, you will find that when you click the button, a procedure named Getanswer is invoked. This is a server-side process that is responsible for:

Creates an instance of the proxy client class.

Call the Ask function of the Eightball WEB service and pass our problem to it.

Sets the text of the Label control to display the answers received from the WEB service.

To create the program, add the following code before closing the tag in the page:

<script runat= "Server" >
Sub getanswer (sender as Object, E as System.EventArgs)
Dim clsEightBall as EIGHTBALLWS = New EIGHTBALLWS
Dim Stranswer as String
Stranswer = Clseightball.ask (Tbquestion.text)
Lblanswer.text = Stranswer
End Sub
</script>  

Check the code roughly.

The <script> tag is a basic script tag, but it can be processed on the server after you add runat= "Server" to it. Then define the getanswer process. Please note that this program requires two parameters: Sender and E. This is the signature required by the Microsoft. NET event handler.

Next, create an instance of the proxy client class. How do we know the class is called EIGHTBALLWS? Using Notepad to check the Visual Basic source files created with WSDL, you see the following code:

Public Class EIGHTBALLWS

Each proxy class has a name associated with it, and is the name used to create a new instance of the class. We call the instance of the Eightballws class to be clseightball. The name is arbitrarily selected.

Next, create a string value (Stranswer) to accommodate the answer returned by the Web service. Remember that we have checked the Web service before and we have determined that there is an action called Ask, which takes a string parameter and returns a string.

Then assign a value to the stranswer by invoking the ask operation of the WEB service and passing our question to the operation.

Stranswer = Clseightball.ask (Tbquestion.text)

The problem is passed to the ask operation by passing the Text property of the TextBox Web Forms Control (tbquestion) that you created earlier. We already know that the ask operation of the WEB service passes the answer back to us as a string. Therefore, after the above line has been executed, Stranswer will contain a string consisting of the answer to the question returned from the Web service.

The only thing left to do is show us the answers we have retrieved. To complete this operation, you need to assign the value contained in Stranswer to the Text property of the Label control.

Lblanswer.text = Stranswer

Save the page now. Make sure the page is saved as 8ball.aspx.

Replication Agent Class

The final step before testing a new ASP.net page is to copy the compiled proxy class to the correct location in the ASP.net application.

1. Create a new folder in the FrontPage site and name it bin.

2. Import the previously compiled 8BallClient.dll file into the folder.

testing the asp.net application

Now we can test the ASP.net application. Browse to the 8ball.aspx page. You will see a text box and a button. Enter the question in the text box and click the button. You will see that the response from the Web service appears below the text box.

Figure 2: Eightball Web Services in action

Summary

In this article, we created a very simple asp.net Web form to use Web services through Microsoft FrontPage. We have demonstrated the benefits of the XML Web service architecture and explained how Web service-specific information can be found by accessing Web services entry points.
Using simple Web services, such as Eightball Web Services, is very easy. If you want to use a complex WEB service, you might want to consider using Microsoft Visual Studio. NET because it provides a powerful toolset for using Web services, and can design asp.net web windows in WYSIWYG (WYSIWYG) environments Body.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.