ASP. NET create XML Web Service full contact (6)

Source: Internet
Author: User

Design Guidelines (1)

It is relatively easy to construct a simple XML Web Service using ASP. NET. However, the real powerful functions of the XML Web Service can be understood only after you have studied the basic structure. The XML Web Service is based on the. NET Framework and the runtime of Public languages. An XML Web Service can use these technologies. For example, the performance, status management, and validation supported by ASP. NET can all be used to construct XML Web Services.

The basic structure of XML Web Services is to build to meet industry standards such as SOAP, XML, and WSDL, and it allows clients of other platforms to interoperate with XML Web Services. As long as a client can send standard-compliant SOAP messages and formatted service descriptions, the client can call an ASP.. NET (regardless of the platform on which the client exists ).

When you construct an XML Web Service using ASP. NET, it automatically supports client communication using SOAP, HTTP-GET, and HTTP-POST protocols. Even if the HTTP-GET and HTTP-POST support passing messages using URL-encoded variable name/variable value pairs, data types that support these two protocols do not support a wide array of SOAP-protocol data types. In SOAP, XML is used to transmit data to XML Web Services or retrieve messages from XML Web Services. You can use the XSD mode that supports a wide range of data type sets to define complex data types. Developers who construct an XML Web Service using ASP. NET do not have to explicitly define complex data types. They can construct only one management class. ASP. NET defines a XSD ing Class to an XSD mode and a ing object instance to XML data for network transmission.

It is important to note that the XML Web Service cannot replace DCOM. We should say that the XML Web Service is a message transmission infrastructure that communicates across the platform that uses industry standards.

Because ASP. NET provides the basic structure for the internal work of XML Web Services, developers can concentrate on implementing their specific XML Web Services. To develop an XML Web Service using ASP. NET, start with the following three steps:

1. Create a file with the. asmx extension.

2. In this file, use an instruction to declare the XML Web Service.

3. Define the XML Web Service method that constitutes the XML Web service function.

XML Web Service is a powerful technology used to provide services that can be accessed over the Internet. The following suggestions will help you create efficient XML Web Services:

The XML Web Service supports both synchronous and asynchronous communication between clients and servers that store XML Web Services. In synchronous communication, the client sends a request to the server to wait for a response. This prevents the client from performing other operations while waiting for the results. However, asynchronous communication causes the client to continue processing other tasks while waiting for the response. The client responds to the service request results when available.

When you use the web service development language tool (wsdl.exe) to create your proxy class, it generates standard, synchronous, and asynchronous versions of the methods in the class. An asynchronous version is composed of two methods: Begin and End. The Begin method is used to initialize the XML Web Service, and the End method gets the result.

Asynchronous Communication can improve system usage and avoid latency when the client waits for XML Web Service results.

The following code example shows how to generate an asynchronous call to the XML Web Service from a customer application.

[C #]
<% @ Page Language = "C #" %>
<% @ Import Namespace = "System. Net" %>
<Html>
<Script language = "C #" runat = "server">
Void EnterBtn_Click (Object Src, EventArgs E)
{
MyMath. Math math = new MyMath. Math ();
// Call to Add XML Web service method asynchronously
// And then wait for it to complete.
IAsyncResult result =
Math. BeginAdd (Convert. ToInt32 (Num1.Text ),
Convert. ToInt32 (Num2.Text ),
Null,
Null );
// Wait for asynchronous call to complete.
Result. AsyncWaitHandle. WaitOne ();
// Complete the asynchronous call to Add XML Web service method.
Float total = math. EndAdd (result );
// Display results in a Label control.
Total. Text = "Total:" + total. ToString ();
}
</Script>
<Body>
<Form action = "MathClient. aspx" runat = server>
<Font face = "Verdana">
Enter the two numbers you want to add and then press
The Total button.
<P>
Number 1:
<Asp: textbox id = "Num1"
Runat = server/>
+
Number 2:
<Asp: textbox id = "Num2"
Runat = server/>
=
<Asp: button id = "Total_Button"
Text = "Total"
OnClick = "EnterBtn_Click"
Runat = server/>
<P>
<Asp: label id = "Total" runat = server/>
</Font>
</Form>
</Body>
</Html>
[Visual Basic]
<% @ Page Language = "VB" %>
<% @ Import Namespace = "System. Net" %>
<Html>
<Script language = "VB" runat = "server">
Sub EnterBtn_Click (Src As Object, E As EventArgs)
Dim math As New MyMath. Math ()
Call to Add XML Web service method asynchronously
And then wait for it to complete.
Dim result As IAsyncResult = _
Math. BeginAdd (Convert. ToInt32 (Num1.Text ),_
Convert. ToInt32 (Num2.Text ),_
Nothing ,_
Nothing)

Wait for asynchronous call to complete.
Result. AsyncWaitHandle. WaitOne ()
Complete the asynchronous call to Add XML Web service method.
Dim addtotal As Single = math. EndAdd (result)
Display results in a Label control.
Total. Text = "Total:" & addtotal. ToString ()
End Sub
</Script>
<Body>
<Form action = "MathClient. aspx" runat = server>
<Font face = "Verdana">
Enter the two numbers you want to add and then press
The Total button.
<P>
Number 1:
<Asp: textbox id = "Num1"
Runat = server/>
+
Number 2:
<Asp: textbox id = "Num2"
Runat = server/>
=
<Asp: button id = "Total_Button"
Text = "Total"
OnClick = "EnterBtn_Click"
Runat = server/>
<P>
<Asp: label id = "Total" runat = server/>
</Font>
</Form>
</Body>
</Html>


To obtain

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.