Reposted (Computer News): Web Service Development Practical Guide (图))

zhaozj2021-02-16  62

Web Service Development Practical Guide Luo Shan Appendix Article

The Web Service platform is a set of standards that define how the application implements interactive operations on the Web. You can use any language you like, write Web Service on any platform, as long as we can query and access these services through the Web Service standard.

This article uses the VB.NET platform to tell you how Web Service development methods and techniques.

First, the composition of the Web Service platform 1. What is the web service from the surface, the Web Service is an application, an API (Application Programming Interface, Application Programming Interface) that can be called via the Web. That is to say, you can use a programming method to implement a feature application.

From a deep level, Web Service is a new web application branch that is self-contained, self-description, modular applications, which can be described in network (usually web), publish, lookup, and through web. transfer.

Web Service is a network-based, distributed modular component, which performs specific tasks, complies with specific technical specifications, which makes Web Service interact with other compatible components. It can use standard Internet protocols to reflect functionality on Internet and intranet.

2. The composition of the web service platform is usually, the Web Service consists of the following three main technical parts:

(1) XML and XSD

XML (Extensible Markup Language, Scalable Markup Language) is the basic format of the data representation in the Web Service platform. XML solves the problem of data representation, but it does not define the standard data type, and it is not defined how to expand the data type. For example, what is the number of plastic surgery? 16-bit, 32-bit, or 64? These details are important to implement interaction. XML Schema (XSD) developed by the W3C (World Wide Web Alliance) is a set of standards that solve this problem. It defines a set of standard data types and gives a language to extend this set of data types. The Web Service platform is using XSD as its data type system. When you write a Web Service application with some programming language (such as VB.NET or C #), in order to comply with the Web Service standard, all the data types you use must be converted to the XSD type.

(2) SOAP

After the Web Service application is written, we need to call it, the SOAP (Simple Object Access Protocol, Simple Object Access Protocol) provides a standard RPC (Remote Procedure Call) method to call the Web Service. The SOAP specification defines the format of the SOAP message, and how to use SOAP through the HTTP protocol. SOAP is based on XML and XSD.

(3) WSDL

WSDL (Web Service Description Language, Web Service Description Language) is an XML-based language that describes Web Service and its functions, parameters, and return values. Because it is based on XML, WSDL is both machine readable and developers can read. Some of the latest developments can generate the WSDL document based on your Web Service, and generate calls corresponding Web Service code.

The workflow of the 3.Web Service Workflow Web Service is shown in Figure 1.

When using the Web Service, 3 phases are included, in Figure 1, three stages of communication flow are listed. Communication in Section 1 is called discovers, which are the main role to determine which services are available on the server. After discovery phase we generally determine which services have been provided in a total of the server. We must also know what kind of interface supports these services before using these services. So the communication of the Web Service Seating 2nd is to send a request to obtain the Web Service Description Language WSDL.

Communication in Section 3 mainly transmits information service requests to the Web Service server, and waits for the server's response.

Second, .NET About Web Service Technical Elements Util. NET Technical Experts Developed to Web Service, we can easily create a web service program. Here are some main technical elements.

1.Web Service Processing The Web Service Processing command provides the necessary information to the ASP.NET environment, such as the class that implements the XML Web Services feature. The following is an example of the Web Service processing instruction in the .asmx file:

<% @ Webservice Language = "VB" codebehind = "service1.asmx.vb" class = "WebService1.service1"%>

Where the Language property indicates the programming language used by the development of XML Web Services. You can create XML Web Services using any language (such as VB.NET or C #). The support code file associated with the .asmx page is indicated by the CodeBehind property. The class attribute indicates a class that supports the XML Web Services feature in the support code file.

Note: To view the contents of .asmx files in .NET's Solution Explorer, please use the .asmx file with right-click. Then click the "Open Mode" command. In the Open Mode dialog, select the Source Code [Text] Editor option, and then click the "Open" button.

2.System.Web.Services.WebService class System.Web.Services.WebService class defines an optional base class for XML Web Services and provides direct access to common ASP.NET objects (such as applications and session status objects). Permission. By default, XML Web Services created in the form of managed code inherits this class using Visual Studio.net. XML Web Services can inherit this class to get access to ASP.NET inherent objects such as Request and session.

If the XML Web Services does not inherit this class, you can also access the ASP.NET inherent objects. Classes that implement XML Web Services must be public and must have a common default constructor (without parameter constructor). This way, ASP.NET can create an instance of the XML Web Services class to process incoming XML Web Services requests.

3. WebService Properties Each XML Web Services requires unique namespaces that allow the client application to divide XML Web Services that may use the same method name. The default namespace for XML Web Services created in Visual Studio .NET is "http://tempuri.org". Although the namespace is similar to a typical URL (Uniform Resource Identifier), it is just a unique identifier in a web browser. The WebService property mainly includes the following properties:

(1) Description attribute

The value of this property contains a descriptive message that will be displayed to XML Web Services for potential users after the descriptive message (such as the service description and service help page) of XML Web Services. (2) Name attribute

The value of this property contains the name of XML Web Services. By default, this value is the name of the class that implements XML Web Services. The Name property identifies the local part of the XML Limit Name of XML Web Services. The Name property is also used to display the name of XML Web Services on the service help page.

(3) Namespace properties

The value of this property contains the default namespace of XML Web Services. The XML namespace provides a method of creating a name in an XML document that can be identified by the URL. Using XML namespaces, you can uniquely identify elements or properties in the XML document. Thus, in the service description of XML Web Services, NameSpace is used as the default namespace of XML elements directly related to XML Web Services. If you do not specify a namespace, use the default namespace "http://tempuri.org".

The following sample code illustrates the usage of the WebService property:

Description: = "You can put some descriptive text.",

Name: = "Myfavoritesservice"> _ _

Public Class Service1

Inherits System.Web.Services.Webservice

'Implement code

END CLASS

4.WebMethod Properties When you create an XML Web Services at managed code, you can specify the method available in XML Web Services by placing the WebMethod property before the public method declares. The Private method does not act as the entry point of XML Web Services, although they can use the same class, and XML Web Services code can call them. The WebMethod property must be applied to each public method that can be used as part of the XML Web Services.

The WebMethod property contains several properties that configure the XML Web Services behavior. For example, you can use this property to provide a short description in the Related Service Help page. WebMethod properties offer the following properties:

(1) BufferResponse properties

When this property is set to True (default), ASP.NET caokes the entire response before sends down the response to the client. Cache is a very effective way to improve performance by reducing communication between the auxiliary process and the Internet Information Services (IIS) process. When set to false, ASP.NET will have a 16KB block. Typically, this property is set to false only if all the contents of the response will be cached in memory. For example, a collection of multiple outflows database is being written. The default value is TRUE unless otherwise specified.

(2) Cacheduration attribute

The value of this property specifies the number of seconds required for the ASP.NET cache each unique parameter setting result. The default value is 0 unless otherwise specified, this setting will disable the result cache.

(3) Description attribute

The value of this property provides an instruction to the XML Web Services method, which is displayed in the Service Help page. The default value is an empty string unless otherwise specified.

(4) Enablesession attribute

When this property is set to false (default setting), ASP.NET will not be able to access the session status of the XML Web Services method. When set to TRUE, XML Web Services can access session status collections directly from HTTPContext.Current.Session; inheriting the WebService base class, you can use the WebService.Session property to access. (5) MessageName properties

The value of this attribute makes XML Web Services to uniquely identify overload using alias. The default value is the method name unless otherwise specified. After the value is specified for the message, the resulting SOAP message reflects this name instead of the actual method name.

(6) TransactionOption properties

The value of this property specifies whether the XML Web Services method can act as the root of the transaction. Although the TransactionOption property can be set to the TRANSActionOption enumeration type, the XML Web Services method has only two possible behavior: it does not participate in the transaction (Disabled, NotSupported, and Supported) or create a new transaction (Required and RequiresNew). The default value is TransactionOption.disabled unless otherwise specified. To use this property, you need to add a reference to System.EnterpriseServices.dll. This namespace contains methods and properties that provide a distributed transaction model that can be found in COM services. The System.EnterpriseServices.ContextUtil class allows you to set the transaction with the Setabort or SetComplete method.

The following sample code illustrates the usage of the webmethod property:

Public Class Service1

Inherits System.Web.Services.Webservice

Cachedure: = 60, _

Description: = "Some descriptive text",

MessageName: = "Retrievedata"> _

Public function getbigchunkofdata () AS Dataset

'Implement code

END FUNCTION

END CLASS

5.xml Web Services Discovery XML Web Services found that the process of positioning and inquiry for XML Web Services is a basic step of accessing XML Web Services. Through the discovery process, the XML Web Services client can understand if an XML Web Services exists in the design phase, and how it functions, and how to interact with it.

However, the Web site that implements XML Web Services does not need to support this discovery process, but is responsible for the service (such as the XML Web Services directory) by another site. In addition, there may be no disclosed methods can be used to find services, such as when creating a private service. XML Web Services found that the following contents:

(1) Static discovery (.disco)

You can enable the XML Web Services discovery by publishing the .disco files (an XML document, including links to other discovery documents, XSD scenarios, and service descriptions). The XML Web Services that automatically created using ASP.NET can provide the generated discovery document. For example, to access the XML Web Services discovered documentation named Service1.asmx (part of the WebService1 item in the local computer), you can use the following URL:

http://localhost/webservice1/service1.asmx? DISCO

The following example shows the structure of the discovery document:

XMLns: wsdl = "http://schemas.xmlsoap.org/disco/wsdl">

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


New Post(0)