Create a WebService + Flash Easy Calculator with VS.NET

zhaozj2021-02-16  51

'=====================

'Reprint, please keep the following information

'Original: Ouyang Dongjie

'

http://www.cnsxml.com

'=====================

After reading this tutorial, you will find that WebService is really simple on .NET!

We want to create a simple WebService using vs.net, his function is to make simple four operations.

Then create a flash to call this WebService

First, create WebService

1. Open Visual Studio .NET.

2. Create a new Active Server Pages (ASP) .NET Web service project. Name the web service is OYDJSERVICE, and specify its location as an appropriate when necessary

When running ASP.NET web server.

3. Change the name of the SOLUTION file to OydjService to remain consistent.

4. Change the name of the default Web service created with Service1.asmx to OydjService.asmx.

5. Click here to switch to the code view to switch to the code view.

6. Define how to encapsulate your service function. Each method provided by this service must be marked with a webmethod attribute. If this property is not, the service will not open this.

method.

Note: Not every method needs to have a webmethod property. Hide some implementation details called by the public web service method are useful, and in the local application is also used

In the case of the WebService class, you also need to hide some implementation details. Local applications can use any utilities, but only methods with webmethod properties can be used as web

Service Remote Access.

Add the following code to your OydJServices class you created in front:

code:

Public Function Add (A as INTEGER, B AS INTEGER) AS Integer Return (A B) End Function Public Function Subtract (A as System.single, B As System.single) AS System .Single Return A - BEnd Function Public Function Multiply (A As System.Single, B As System.Single) As System.Single Return A * BEnd Function Public Function Divide (A As System. SINGLE, B AS System.single) As system.singleif B = 0 Return -1END IFRETURN CONVERT.TOSINGLE (A / B) End Function

Generate a web service: From the Generative Menu, select Generate.

This web service can be tested by turning to the OydjService.asmx Web service page. If your page is placed on a local computer, then the URL will be

http://localhost/oydjservice/oydjService.asmx.

Running ASP.NET will return a Web service help page to illustrate this web service. This page also allows you to test different web services.

Second, create a flash to call this WebService

1. New Flash

2. Drag into 2 text boxes (Textarea), named: T1, T2, respectively

3. Drag into the drop-down menu (ComboBox), named: YSF, and fill in "Data" attribute: "[1, 2, 3, 4]", "Labels" attribute: "[ , -, *, ÷ ]

4. Drag into a dynamic text box, named: Convert

5. Drake a button (Button), named: Search

6. Drake into a WebServiceConnector component

7. Edit "Action" at the first frame, join the following code

code:

Import mx.services. *; // Set the WSDL address VAR WSDLURI = "http://localhost/oydjservice/oydjService.asmx? WSDL"; ws = new webservice (wsdluri); // point the button and start connecting WS and calculates Search.onpress = function () {// Perform Switch (YSF.SelectedItem.data) {Case 1: Callback = WS.Add (t1.text, t2.text); Break; Case 2: Callback = ws.subtract ( T1.Text, T2.Text); Break; Case 3: Callback = ws.multiply (t1.text, t2.text); Break; Case 4: Callback = ws.divide (t2.text, t1.text); BREAK } // Web service successful transfer information callback.onResult = function (result) {convert.text = result;} // Web service error transfer information callback.onfault = function (fault) {for (i in fault) { TRACE (i ":" fault [i]);}}}

Third, demonstration (because my WebService server is not stable, it is possible not to display correctly) three, flash original file download http://cnsxml.com/demo/webs_flash/jj.fla

转载请注明原文地址:https://www.9cbs.com/read-23951.html

New Post(0)