ASP.NET+Web service realizes software sharing
Author:Eve Cole
Update Time:2009-06-30 15:39:48
Abstract This article proposes a new method of software sharing through software function sharing. The advantage of this method is that it realizes the sharing of software functions in the form of remote invocation of Web services without copying the software to the client and also reduces the cost. Some resource redundancy on the network is also conducive to sharing existing Web services and integrating new systems. Moreover, this article analyzes the effectiveness of this new method through an example of the student identity verification module.
introduction
Traditional software sharing is to copy the software from the network server to the client to realize software sharing. The disadvantage of this method is that every client that needs to use the software must copy the software first, resulting in space redundancy on the network. This results in a large amount of isolated data and duplicate business logic.
Web services provide a viable solution for achieving data and system interoperability by enabling data exchange and remote invocation of application logic using XML messaging, enabling data to pass through firewalls, and moving data between heterogeneous systems. .
This article proposes a new method of software sharing through software function sharing to address traditional software sharing issues. The advantage of this method is that software function sharing is achieved in the form of remote invocation of Web services without copying the software to the client. It also reduces some resource redundancy on the network, and is also conducive to sharing existing Web services and integrating new systems. Moreover, this article analyzes the effectiveness of this new method through an example of the student identity verification module.
The meaning of software sharing
With the popularization and development of computer applications, practical computer software has been developed and applied in various industries and as small as a company or department. These software have greatly improved the work efficiency and modern management level of the company, and it has become the core of the business operation and management of the company. But the widespread adoption of custom software in almost every department in most companies has resulted in a large number of useful but siled and repetitive chunks of business logic. If duplication of design can be avoided during design and development, and software function sharing is used to achieve the same functions of each module, it will greatly save software development costs and provide a good architectural foundation for future system upgrades and integration. In addition, existing business logic can be shared with other applications through a small amount of improvements, thereby reducing development costs.
Because the environments in which each application is developed are diverse and technology is constantly evolving, sharing existing applications to create a feature set has been difficult in the past. Fortunately, the emergence of Web Services technology has made it possible to realize software sharing. The Web service of software functions provides business logic that can be shared within the Internet, and ultimately forms an openness based on various Web services. functional component system. Next, we will discuss how to use Web Services technology to realize software sharing.
Software sharing based on Web Services technology
1. Introduction to Web Services technology
Web Services can be regarded as APIs deployed on the Internet, which can be easily integrated and called by applications and even other Web Services to form new application services. It has complete encapsulation, loose coupling, and high integration capabilities. There is no doubt that Web Services technology will become the mainstream technology of the next generation of Web, which is the embodiment of "software as a service".
The Web Services architecture is as follows, consisting of service requester, service agent and service provider:
The Web service provider is the owner of the Web service. It registers with the service agent to configure and publish the service, and waits patiently to provide its own functions to other services and users; the Web service requester is the user of the Web function, which uses lookup Operation to retrieve the service description from the service broker, then bind to the service provider and invoke or interact with the Web service.
A Web service provider is equivalent to an intermediary, which connects a Web service requester with an appropriate Web service provider, usually UDDI. UDDI provides a mechanism for dynamically finding Web services for service requesters.
2. Implementation of software sharing based on Web Services
In the process of software development, people often divide the software into different modules according to functions to facilitate the reorganization, reuse, modification and upgrade of module functions. To realize software sharing through Web Services technology, it is also necessary to first divide the integrated system into modules according to functions; then, create Web services to implement these functional modules; in order to make Web services accessible, it is also necessary to publish service descriptions (deploy Web services) so that other modules can It can be found and called. In this way, software functions implemented as Web services can be shared by applications and even other Web services.
When service requesters such as applications or other Web services need to call Web services, they first retrieve the service description or query the required service type in the service registration center. When the required service is found, the service description can be used to bind to the service provider and call the corresponding service.
Microsoft's newly launched flagship product Visual Studio.NET is known as the preferred tool for developing Web services. Using Visual Studio.NET can easily create and call Web services. Below, a specific example of software sharing based on Web Services technology will be given.
3. Application examples of software sharing: shared implementation of student identity verification module.
Currently, there are many software systems in colleges and universities, such as course selection systems, grade query systems, online course systems, library systems, student financial systems, etc. Since each system is independent of each other, each system has a student identity verification module, which results in functional duplication of design; in addition, each system is independent of each other, and students need to remember passwords for different systems.
In view of the above situation and the current highly developed campus network, we can completely use Web services to realize the sharing of student identity verification modules. The following will introduce the process of creating and calling the student identity authentication web service using C# language using the Visual Studio.NET environment.
1) Creation of Web services
The student identity authentication module consists of 1 web service:
public Boolean ValidUser(string userID,string Pwd)
Web service ValidUser is used to verify student identity. A basic student information table Student has been created in the Sql Server database StudentsInfo, in which the fields UserID and Pwd store the student's user code and password respectively.
The following will introduce the creation process of Web services in detail:
a Run the Visual Studio.NET development environment and create a new "ASP.NET Web Service" type project WSStudentLogin.
b Specific code implementation of Web services.
using System.Data.SqlClient;
//Omit code...
public class Service1 : System.Web.Services.WebService
{
string ConStr="";
ConnStr="DATABASE=StudentsInfo;SERVER=10.1.111.19;UID=sa;PWD=;";
//Omit code...
[WebMethod]
public Boolean ValidUser(string userID,string Pwd)
{
Boolean flag=false;
string sqlStr="";
//Create a database connection object
SqlConnection tempConn=new SqlConnection(ConnStr);
sqlStr="select * from student where ID='"+userID+"' and pwd='"+Pwd+"';";
//Create a command object
SqlCommand tempComm=new SqlCommand(sqlStr,tempConn);
tempConn.Open();
SqlDataReader tempReader=tempComm.ExecuteReader(CommandBehavior.CloseConnection);
if (tempReader.HasRows) flag=true;
tempReader.Close();
tempComm.Dispose();
return flag;
}
}
It should be noted that only the methods described with [WebMethod] are Web services that can be called remotely. Therefore, [WebMethod] in front of the method cannot be omitted.
To make a web service available to others, it must be deployed to a web server accessible to the clients you wish to support. To deploy the web service to a server other than the development server, you can add a web installation project or copy the required files to the target server. Due to space limitations, this article does not discuss this in depth. It is assumed that the Web service in this example is deployed on the development server.
After creating and deploying the Web service, we can call the corresponding Web service on the client. The following describes how to locate and reference Web service functions on the client.
2) Web service call
The process of using a Web service is actually the process of binding the Web service user to the Web service and calling its methods. To simplify the binding process. Visual Studio.NET provides methods of service proxy classes. The service proxy class generates a local class based on the Web service description document (XXX.WSDL). During the execution process, the client uses the information in the proxy class to access the Web service and implement the actual method invocation. Visual Studio.NET provides us with a simple way to achieve this process:
a Create a Web service access client program.
Web service access client programs can be various types of applications or other Web services. Here, we create a new project WebApplication2 of type "ASP.NET WEB Application".
b. Service reference.
First, click Add Web Reference on the Project menu. Next, because the Web service in this example is located on the local computer, we click the "Web service on the local computer" link in the browser pane. Then, click the Service1 link from the list provided to retrieve information about the web service. Then, click Add Reference to add a web reference to the target web service. Visual Studio.NET will download the service description and generate a proxy class that serves as the interface between the application and the Web service.
c. Specific code examples for calling Web services in client programs.
private void Button1_Click(object sender, System.EventArgs e) { //Create proxy class object localhost.Service1 ClientProxy=new localhost.Service1(); try {//Access Web services through code class objects if (ClientProxy.ValidUser(TxtUserId.Text,txtPwd.Text)) Label1.Text="OK"; else Label1.Text="ERROR" ; } catch(e) {throw e;} finally {ClientProxy.Dispose();} } |
other
Web Services technology provides a good technical foundation for the realization of software sharing and system integration based on existing information systems. However, it is necessary to make software sharing based on Web Service technology truly practical. We also need to solve the following issues: first, security and reliability, first, the connection reliability of Web service network transmission, and second, the reliability of Web service content, that is, ensuring data integrity and confidentiality. The second is the control of service usage rights. Web services are the embodiment of "software as a service". Who is prohibited from using this service, who is allowed to use this service, how to charge for using this service, etc., all need to be solved in actual use. problem. In addition, issues such as the carrying capacity of Web services, the deployment and discovery of Web services, and the failure handling of Web service calls by customers are also issues that need to be resolved.
summary
This paper proposes the realization of software sharing from the perspective of software function sharing, discusses the use of Web Services technology to realize remote software function sharing, and uses the student body verification module to analyze the effectiveness and advantages of software function sharing. The research on software function sharing is of great significance to the realization of distributed computing, and it requires further research.